Some daily Maven tasks

This page features common Maven tasks you will likely use while developing Java/Kotlin applications. This is more like a draft of the commands I usually meet and I will try to update them from time to time.

Latest version of Maven  I’ve been using is the 3.8.1.

MAVEN

Reminder of the stages :

  1. validate – validate the project is correct and all necessary information is available
  2. compile – compile the source code of the project
  3. test – test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
  4. package – take the compiled code and package it in its distributable format, such as a JAR.
  5. verify – run any checks on results of integration tests to ensure quality criteria are met
  6. install – install the package into the local repository, for use as a dependency in other projects locally
  7. deploy – done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.

Escape one module for testing :

$ mvn -pl ‘!a_module,!other_module’ install

From where you left :

$ mvn clean install -rf :your-module

Multi threaded :

$ mvn clean test -T1C

Only one module and its dependencies :

$ mvn clean install -pl ‘your_module’

One module and sub modules :

$ mvn clean install -f :your_module

Run only one test:

$ mvn -Dtest=RobotTest#test1 verify -pl the_module

See unused dep

mvn dependency:analyze -pl your_module

Display plugin updates :

mvn versions:display-plugin-updates

Alter the version of Java

Temporarly (session duration) :

$ export JAVA_HOME="/opt/jdk-12.0.1"

Using jenv

jenv

jenv shell 11.0.2

Optimization

See maven-build-scanner project to check for an extension to analyse the maven process.

Trick 1

Disable jacoco :

mvn clean test -Djacoco.skip=true

Compiler plugin

Clean command

Short Guide Going further

-> delete all previously compiled Java .class files and resources (like .properties) in your project. Your build will start from a clean slate.

Why issue the clean phase ?

-> It’s great for when you hit a weird caching issue or some obscure bug that you have but nobody else is able to reproduce.

Offline

mvn install –offline

No JIT while running mvn

MAVEN_OPTS= -XX:+TieredCompilation -XX:TieredStopAtLevel=1

mvn -T 1C install -pl :your-specific-module -am —offline

OPTIMIZATION & MAVEN

Maven build Scanner

The maven build scanner could also be used in order to scan for spots to improve.

some doc

Maven cache

Maven extensions

Speed up the build

speed up

Jrebel

MAVEN_OPTS= -XX:+TieredCompilation -XX:TieredStopAtLevel=1

disable jacoco plugin

-Djacoco.skip=true

Gradle cache enterprise

Reuse output of previous builds (https://docs.gradle.com/enterprise/tutorials/caching/)

  • when compile same source code (no change) -> identical bytecode

    -> way to track to identify by a hash key (source, classpath, goal) keep the key and reuse.

mvn version set

Set Maven version

ex: set the version to all modules at once :

mvn versions:set -DnewVersion=1.2.3

All pom should share the same version – look at the warning when issuing the command to search for some misspelling !

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Want more information?

Related links will be displayed within articles for you to pick up another good spot to get more details about software development, deployment & monitoring.

Stay tuned by following us on Youtube.

%d bloggers like this: