Maven, one of the central actors in the Java World, resposible for managing the building life-cycles of many projects, is full of little features, that sometimes we forget to explore.
Let us go straight away and take a look at some very useful Maven features that will make your builds shine.
Sometimes it is needed to build a bunch of projects all together, artifact-a, artifact-b and so on. What do we usually do when one of them fail? Build it all again!
But not anymore:
By using this option you can run the build from the project that failed.
Two out of ten
Let us go straight away and take a look at some very useful Maven features that will make your builds shine.
From where it stopped
Sometimes it is needed to build a bunch of projects all together, artifact-a, artifact-b and so on. What do we usually do when one of them fail? Build it all again!
But not anymore:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn -rf yourprojects-module clean install |
By using this option you can run the build from the project that failed.
Two out of ten
Ok, suppose you have 10 projects, and you only want to build 2 of them, how would you do?
The option -pl will do the job
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn -pl artifact-a,artifact-b clean install
Multi-threaded Build
If in the machine you run the build you have many Cores, tou can take advantage of them by using the following option(it means 2 Threads per Core):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn clean install -T2C
It is also possible to define 3 Threads per Core(T3C)
Skip your Tests when you want to
With a lot of tests to perform your complete phases might really take too long and sometimes you only want to test a new or small functionality, you might skip the Tests by using the DskipTests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn clean install -DskipTests
Running Offline
Wanna run your builds without maven connecting to repositories, checking for updates? You asked you got it!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn clean install -o
When running with the offline option enabled, Maven will not attempt to connect to a remote repository to retrieve artifacts.
Bonus - Deal with failures
The
following options control how Maven reacts to a build failure in the middle of
a multi-module project build:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-fae, --fail-at-end
Only fail
the build afterwards; allow all non-impacted builds to continue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-ff, --fail-fast
Stop at
first failure in reactorized builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-fn, --fail-never
NEVER fail
the build, regardless of project result
The -fn and
-fae options are useful options for multi-module builds that are running within
a continuous integration tool like Hudson. The -ff option is very useful for
developers running interactive builds who want to have rapid feedback during
the development cycle.
That's all for today, hope your builds will never be the same...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn -pl artifact-a,artifact-b clean install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn clean install -T2C |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn clean install -DskipTests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mvn clean install -o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-fae, --fail-at-end |
Only fail the build afterwards; allow all non-impacted builds to continue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-ff, --fail-fast |
Stop at first failure in reactorized builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-fn, --fail-never |
NEVER fail the build, regardless of project result
Comments
Post a Comment