6

我有一个带有父项目的传统 Maven 设置和一些子项目的模块。当我这样做时,它会按顺序(深度优先)为每个项目mvn deploy运行整个生命周期(包括test) 。deploy如果任何项目无法构建,我想避免部署任何子项目。换句话说,我希望deploy整个父项目是“全有或全无”。有什么办法可以做到这一点?

4

2 回答 2

8

Maven 本身(还)不能做到这一点。目前,构建过程单独运行每个模块上的所有目标。有计划让目标看到全局,但这可能是针对 Maven 4 的。

同时,您可以使用一个小的 shell 脚本:

 mvn clean install && mvn deploy -DskipTests=true

第一次运行构建了一切。第二次运行不会做太多(所有代码都已经编译并且跳过了长时间的测试),所以它非常快。

我实际上更喜欢这种方法,因为我的脚本还将任何现有distributionManagement元素替换为我公司缓存的元素。这意味着我可以为我的公司部署任何项目,而无需对原始 POM 进行任何更改。这是脚本:

#!/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

要旨

于 2012-10-08T13:11:07.553 回答
3

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!

于 2012-10-08T14:21:02.590 回答