build-helper-maven-plugin:无法与其他插件一起使用替换值 [英] build-helper-maven-plugin: unable to use replaced value with other plugins

查看:140
本文介绍了build-helper-maven-plugin:无法与其他插件一起使用替换值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google App Engine标准Maven项目,该项目是使用appengine-standard-archetype原型创建的.

I have a Google App Engine Standard Maven project, which I created with the appengine-standard-archetype archetype.

我想使用${project.version}变量作为部署版本,但是某些字符不允许使用该值:

I want to use the ${project.version} variable as deploy version, but the value is not allowed for certain characters:

只能包含小写字母,数字和连字符.必须开始 并以字母或数字结尾.不得超过63个字符.

May only contain lowercase letters, digits, and hyphens. Must begin and end with a letter or digit. Must not exceed 63 characters.

0.0.1-SNAPSHOT需要修改.然后,我使用build-helper-maven-plugin来获取替换项

The value 0.0.1-SNAPSHOT need to be modified. I then used the build-helper-maven-plugin to obtain the replacement

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>version-urlsafe</id>
            <goals>
                <goal>regex-property</goal>
            </goals>
            <configuration>
                <name>project.version.urlsafe</name>
                <value>${project.version}</value>
                <regex>\.</regex>
                <replacement>-</replacement>
                <toLowerCase>true</toLowerCase>
                <failIfNoMatch>false</failIfNoMatch>
            </configuration>
        </execution>
    </executions>
</plugin>

maven-antrun-plugin显示值

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>regex-replace-echo</id>
            <phase>package</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <echo>******** Displaying value of property ********</echo>
                    <echo>${project.version.urlsafe}</echo>
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>

最后,我将新属性用作部署的版本

At the end I used the new property as version for deploy

<app.deploy.version>${project.version.urlsafe}-urlsafe</app.deploy.version>

请注意,我在值的末尾添加-urlsafe只是为了理解为什么不考虑该值

Note that I add the -urlsafe at the end of the value only to understand why the value is not considered

使用mvn appengine:deploy运行部署

...

[INFO] Executing tasks

main:
     [echo] ******** Displaying value of property ********
     [echo] 0-0-1-snapshot

...

gcloud.cmd app deploy --version ${project.version.urlsafe}-urlsafe
[INFO] GCLOUD: ERROR: (gcloud.app.deploy) argument --version/-v: Bad value [${project.version.urlsafe}-urlsafe]

即使ant-run插件正确地呼应了新版本,在构建deploy命令时,变量本身也会丢失.

Even if the ant-run plugin properly echoed the new version, when the deploy command is built, the variable itself is missing.

然后我尝试在部署之前强制执行regex-property目标,如下所示

I then tried forcing the regex-property goal before the deploy, like follows

mvn build-helper:regex-property appengine:deploy

但是在这种情况下,我会丢失配置错误:

but I'm getting a missing configuration error in this case:

[ERROR] Failed to execute goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:regex-property (default-cli) on project maventest: The parameters 'regex', 'name', 'value' for goal org.codehaus.mojo:build-helper-maven-plugin:3.0.0:regex-property are missing or invalid -> [Help 1]

一点题外话: 由于以前的类似案例,我决定手动运行build-helper:regex-property作为附加目标:缺少一个插入新变量的插件,该插件可以正确回显,但在使用该值时会丢失.这里是参考:无法获得git.branch属性

A little digression: I decided to manually run the build-helper:regex-property as additional goal due to a previous experience with a similar a case: a plugin that inject a new variable, which is properly echoed but when it comes to use the value, is missing. Here is the reference: Unable to obtaing git.branch property

与插件作者合作,我们发现在appengine之前添加插件目标可以解决问题mvn git-commit-id:revision appengine:deploy.最后,此问题的根本原因是Maven错误: https://issues. apache.org/jira/browse/MNG-6260

Cooperating with the plugin author we found that adding the plugin goal before the appengine one can solve the issue mvn git-commit-id:revision appengine:deploy. At the end the root cause of this problem was a Maven bug: https://issues.apache.org/jira/browse/MNG-6260

因此,由于插件配置错误,即使直接调用插件的解决方法在这种情况下也不适用.

So even the workaround of directly calling the plugin is not suitable in this case due to a plugin configuration error.

如何解决问题?在执行Appengine部署时,如何获取正确创建的${project.version.urlsafe}变量?

How can issue can be solved? How can I obtain the ${project.version.urlsafe} variable properly created when executing the appengine deploy?

推荐答案

我在使用appengine-maven-plugin时遇到了同样的问题.没错,在应用引擎上进行部署之前,您需要先调用目标build-helper:regex-property. 但是要使此工作有效,您必须将配置部分移到executions标记之外. 这是我当前正在使用的完整配置:

I had the same problem using the appengine-maven-plugin. And you're right, you need to first call the goal build-helper:regex-property before deploying on app engine. But to make this work, you have to move the configuration part outside the executions tag. Here is the complete configuration I am currently using:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <version>3.0.0</version>
  <configuration>
    <name>project.version.urlsafe</name>
    <value>${project.version}</value>
    <regex>\.</regex>
    <replacement>-</replacement>
    <toLowerCase>true</toLowerCase>
    <failIfNoMatch>false</failIfNoMatch>
    <fileSet/>
    <source/>
  </configuration>
</plugin>

然后,在调用mvn build-helper:regex-property appengine:deploy时,一切都会按预期进行.

Then when calling mvn build-helper:regex-property appengine:deploy, everything should work as expected.

这篇关于build-helper-maven-plugin:无法与其他插件一起使用替换值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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