Maven build-helper-maven-plugin 正则表达式无法使用属性作为dependency.version [英] Maven build-helper-maven-plugin regex unable to use property as dependency.version

查看:30
本文介绍了Maven build-helper-maven-plugin 正则表达式无法使用属性作为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆