作为发布过程的一部分,我使用 mvn versions:use-releases
目标是用已发布的版本替换所有 -SNAPSHOT 依赖项。在此之后,我想检查所有 SNAPSHOT 依赖项是否已被版本替换。
问题 : 怎么查?
我知道,maven 发布插件执行这样的检查作为 release-prepare
的一部分目标,但我不想使用发布插件。
最佳答案
您可以使用 maven-enforcer-plugin
仔细检查任何 SNAPSHOT 依赖项是否仍然存在。
来自 the official example其requireReleaseDeps
规则:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce-no-snapshots</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireReleaseDeps>
<message>No Snapshots Allowed!</message>
</requireReleaseDeps>
</rules>
<fail>true</fail>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
请注意
fail
元素设置为 true
,在这种情况下,如果有 SNAPSHOT
,构建将失败发现依赖。您可以将此类配置放在 maven profile 中并在需要时激活它(因此每当必须执行此检查时)。
关于Maven 检查所有依赖项是否已发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38113721/