我正在研究用 nexus-staging-maven-plugin 替换 maven-deploy-plugin。
现在我项目的一些子模块(例如集成测试模块)不会部署到Nexus服务器上。我曾经通过“maven.deploy.skip”属性禁用这些模块的部署。不过,我找不到任何可与 nexus-staging-maven-plugin 相媲美的东西。是否有另一种方法可以使用此插件从部署中跳过单个模块?
我还尝试将插件绑定到伪阶段“无”,如 here 所述,但检查有效的 POM,仍然有插件的注入执行(我假设这是由于它的方式替换现有的部署插件)。
我发现处理 nexus-staging-maven-plugin 限制的最简单方法是将您不想部署的任何模块隔离到单独的 Maven 配置文件中,并在部署发生时将其排除。例子:
<profile>
<id>no-deploy</id>
<!--
According to https://github.com/sonatype/nexus-maven-plugins/tree/master/staging/maven-plugin
skipNexusStagingDeployMojo may not be set to true in the last reactor module. Because we don't
want to deploy our last module, nor a dummy module, we simply omit the relevant modules when
a deploy is in progress.
-->
<activation>
<property>
<name>!deploy</name>
</property>
</activation>
<modules>
<module>test</module>
<module>benchmark</module>
</modules>
</profile>
在上面的示例中,我避免构建和部署“测试”和“基准”模块。如果您想在不部署的情况下运行单元测试,请使用单独运行:
mvn test
mvn -Ddeploy deploy
面临类似的问题。对我有用的解决方案是在需要从部署任务中排除的模块中添加 skip 为 true 的部署插件。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
因为所有其他答案都不适用于我的设置,所以我最终得到一个设置,您可以在其中明确禁用所有模块,但主模块(或您喜欢的任何其他组合)。
将以下配置文件添加到您的主 pom
<!-- this is a workaround to be able to only deploy the main module used in deploy phase, nexus stage plugin is buggy -->
<profiles>
<profile>
<id>allmodules</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<modules>
<module>modules/module1</module>
<module>modules/module2</module>
<module>modules/module3</module>
</modules>
</profile>
<profile>
<id>mainmodule</id>
<modules>
<module>modules/module1</module>
</modules>
</profile>
</profiles>
在此示例中,您只想部署来自
module1
的工件,并且您有 3 个模块:module1
、module2
和 module3
。由于默认情况下所有模块都是活动的,因此“正常”的 Maven 目标应该像以前一样运行。部署简单地做:
mvn verify nexus-staging:deploy -P !allmodules,mainmodule
停用
allmodules
配置文件,同时激活mainmodule
.