我想在maven中根据是否是快照构建有条件地设置一个属性。
if ${project.version} ends with "-SNAPSHOT"
then
deployFileUrl = ${project.distributionManagement.snapshotRepository.url}
else
deployFileUrl = ${project.distributionManagement.repository.url}
如何在maven中实现这一点?
我使用build-helper-maven-plugin进行了如下尝试
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>regex-properties</id>
<goals>
<goal>regex-properties</goal>
</goals>
<configuration>
<regexPropertySettings>
<regexPropertySetting>
<name>deployFileUrl</name>
<value>${project.version}</value>
<regex>.*-SNAPSHOT</regex>
<replacement>${project.distributionManagement.snapshotRepository.url}</replacement>
<failIfNoMatch>false</failIfNoMatch>
</regexPropertySetting>
</regexPropertySettings>
</configuration>
</execution>
</executions>
</plugin>
这种方法的问题是我不能实现else-condition。
3条答案
按热度按时间avwztpqn1#
要根据快照生成(或其他条件)将该属性设置为两个不同的值,可以使用以下命令:
它将
dockerTag
属性设置为dev
或latest
,具体取决于构建类型。如果要更改属性值,则应在两个位置更改。例如,对于
true
和false
,请使用<value>${project.version} true false</value>
和<regex>(?=.*SNAPSHOT).*(true).*|.*(false).*</regex>
。gkl3eglg2#
最后我使用了maven-antrun-plugin,如下所示
huwehgph3#
如果你的版本号是一个发布版本,如
1.2.3
,maven将使用发布仓库,如果版本是一个SNAPSHOT版本,如'1.2.3-SNAPSHOT`,maven将使用快照仓库。