Make parent project maven check all modules before deploying any of them

I have a traditional maven setup with a parent project and several modules that are subprojects. When I execute mvn deploy , it starts the full life cycle (including test ) to deploy for each project sequentially (in depth). I would like to avoid deploying any subprojects if any of the projects is not created. In other words, I would like the deploy entire parent project to be "all or nothing." Is there any way to achieve this?

+6
source share
2 answers

If your remote repository is an instance of Sonatype Nexus Pro, then the Staging tool for Nexus Pro will allow atomic publishing to the repository itself.

If you use Jenkins, there is a deployment delay plugin that will deploy all your artifacts as a post-build action (or a very post-build) (doesn't remember too much which repository manager you use)

Finally, one of my medium-term goals for mrm-maven-plugin @codehaus is to allow a local deployment setup so that you can do something like

 mvn mrm:catch-deploy deploy mrm:push-deploy 

BUT that the latter has not yet been written!

+3
source

Maven itself cannot do this (yet). Currently, the build process performs all the tasks for each module separately. Plans allow targets to see the big picture, but perhaps for Maven 4.

At the same time, you can use a small shell script:

  mvn clean install && mvn deploy -DskipTests=true 

The first launch creates everything. The second run will not do much (all code has already been compiled and long tests have been skipped), so it is pretty fast.

I really prefer this approach because my script also replaces any existing distributionManagement elements with those for my company cache. This means that I can deploy any project for my company without making any changes to the original POM. Here is the script:

 #!/bin/bash if [[ ! -e pom.xml ]]; then echo "Missing pom.xml" 1>&2 exit 1 fi sed \ -e '/<distributionManagement>/,/<\/distributionManagement>/d' \ -e '/<\/project/d' \ pom.xml > pom-deploy.xml || exit 1 cat >> pom-deploy.xml <<EOF <!-- ADDED BY $0 --> <distributionManagement> ... whatever you need ... </distributionManagement> </project> EOF mvn -f pom-deploy.xml clean install && \ mvn -f pom-deploy.xml deploy -DskipTests=true && \ rm pom-deploy.xml exit 0 

gist

+8
source

Source: https://habr.com/ru/post/927185/


All Articles