【问题标题】:build-helper-maven-plugin: unable to use replaced value with other pluginsbuild-helper-maven-plugin:无法将替换值与其他插件一起使用
【发布时间】:2017-09-11 06:05:32
【问题描述】:

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

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

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

0.0.1-SNAPSHOT 的值需要修改。然后我使用build-helper-maven-plugin 来获取替换

<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>

最后我使用新属性作为部署版本

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

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

使用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 插件正确地回显了新版本,当构建部署命令时,变量本身也丢失了。

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

mvn build-helper:regex-property appengine:deploy

但在这种情况下,我遇到了缺少的配置错误:

[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 作为附加目标,因为之前有类似案例的经验:一个注入新变量的插件,该变量已正确回显,但在使用该值时,丢失了。这是参考:Unable to obtaing git.branch property

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

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

如何解决问题?执行appengine deploy时如何获取正确创建的${project.version.urlsafe}变量?

【问题讨论】:

    标签: regex maven google-app-engine


    【解决方案1】:

    我在使用appengine-maven-plugin 时遇到了同样的问题。你是对的,你需要先调用目标build-helper:regex-property,然后再部署到应用引擎上。 但要使其工作,您必须将配置部分移到executions 标记之外。 这是我目前使用的完整配置:

    <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 时,一切都应该按预期工作。

    【讨论】:

      猜你喜欢
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-19
      • 2013-02-19
      • 1970-01-01
      • 1970-01-01
      • 2018-11-03
      相关资源
      最近更新 更多