I have a traditional maven setup with parent project and a number of modules what are sub-projects. When I do mvn deploy
, it runs the full lifecycle (including test
) up to deploy
for each project in sequence (depth-first). I would like to avoid deploying any subprojects if any of projects fails to build. In other words I would like the deploy
of the whole parent project to be "all or nothing". Is there any way to achieve this?
We can create our own pom. xml file, which will serve us as the parent project. Then we can include in it all configuration with dependencies, and set it as the parent of our child modules, so they'll inherit from it. Besides the inheritance, Maven provides the notion of aggregation.
Maven itself can't do this (yet). Currently, the build process runs all targets on each module individually. There are plans to allow targets to see the big picture but that's probably for Maven 4.
In the mean time, you can use a little shell script:
mvn clean install && mvn deploy -DskipTests=true
The first run builds everything. The second run won't do much (all the code is already compiled and the long tests are skipped), so it's pretty fast.
I actually prefer this approach because my script also replaces any existing distributionManagement
elements with the ones for my company's cache. This means I can deploy any project for my company without needing to make 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
If your remote repository is a Sonatype Nexus Pro instance, then the "Staging" facility of Nexus Pro will allow for atomic publishing to the repository proper.
If you are using Jenkins, there is a delayed deployment plugin that will deploy all your artifacts as a post-build (or very post-build) action (doesn't mind too much which repository manager you use)
Finally, one of my medium-long-term goals for the mrm-maven-plugin @ codehaus is to allow local staging of deployment so that you will be able to do something like
mvn mrm:catch-deploy deploy mrm:push-deploy
BUT that last one is not written yet!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With