Maven build-helper-maven-plugin正则表达式无法使用属性作为dependency.version [英] Maven build-helper-maven-plugin regex unable to use property as dependency.version
问题描述
我正在尝试使用build-helper-maven-plugin正则表达式转换默认属性,然后再在依赖项部分中使用它.
I'm trying to use the build-helper-maven-plugin regex to convert a default property before it is used in the dependency section.
我的pom.xml文件属性部分看起来像这样...
My pom.xml file property sections looks like this...
<properties>
<some.version>114.6.9</some.version>
</properties>
我的pom.xml文件构建插件部分看起来像...
My pom.xml file build plugin section looks like...
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9</version>
<executions>
<execution>
<id>regex-property</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>some.version</name>
<value>${P_SOME_VERSION_AS_PASSED_BY_JENKINS}</value>
<regex>^dirtyPrefix-(\S*)</regex>
<replacement>$1</replacement>
<failIfNoMatch>false</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
我的pom.xml依赖版本看起来像...
My pom.xml dependency version looks like...
<dependencies>
<dependency>
<groupId>someArtifactGroup</groupId>
<artifactId>someArtifact</artifactId>
<version>${some.version}</version>
</dependency>
</dependencies>
这样的想法是,如果使用Jenkins并通过了一个依赖项覆盖,它将被删除其前缀,并使用其代替默认值.
但是,似乎该插件在验证依赖项之前未运行-是否有可能使该插件正常工作?或者有更好的方法吗?
The idea being that if Jenkins is used and passes a dependency override it will be stripped of its pre-fix and used instead of the default value.
However it appears that this plugin does not run before the dependencies are validated - is it possible to get this working or is there a better way?
推荐答案
我当时也处于类似情况,但是用-D覆盖不是解决方案(请不要问),因为我有一些建议变量,配置文件也不是.
I was kind of in a similar situation, but an override with -D is no solution (just don't ask) and since I've got a few variables, profiles are none either.
在我的情况下是这样的: fabric8 docker maven插件使用一个变量. 该变量由"build-helper-maven-plugin"正则表达式属性生成.
In my case it's like this: The fabric8 docker maven plugin uses a variable. That variable is generated by the "build-helper-maven-plugin" regex-property.
如果调用了"mvn docker:build",则不使用验证阶段,也不存在变量(因此我得到了"$ {blabla}"文字),并且构建失败. 如果我调用通常的构建,则会创建该变量.
If "mvn docker:build" is invoked, the validate phase is not used and the variable is not there (so I get a "${blabla}" literal) and the build fails. If I invoke the usual build, the variable gets created.
我采取了执行"mvn validate docker:build"而不是"mvn docker:build"的策略来强制执行验证步骤,因此创建了变量.
I took the strategy to run "mvn validate docker:build" instead of "mvn docker:build" to force the validation step, so the variable gets created.
这篇关于Maven build-helper-maven-plugin正则表达式无法使用属性作为dependency.version的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!