首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用构建助手-maven-plugin

使用构建助手-maven-plugin
EN

Stack Overflow用户
提问于 2019-06-12 21:41:43
回答 1查看 1K关注 0票数 0

我有下面的pom.xml。

我希望使用以下命令将一个tag属性传递给我的构建:

mvn clean package -Dtag=test

它应该将该属性拆分为另外两个属性,my.groupmy.version,然后使用它在URI中使用xldeploy-maven-plugin (https://docs.xebialabs.com/xldeploy-maven-plugin/6.0.x/)构建XLDeploy包。

我的问题是,regex-properties的目标实际上就是完成这项工作,我可以看到,多亏了maven-antrun-plugin

代码语言:javascript
复制
[INFO] --- maven-antrun-plugin:1.1:run (default) @ myArtifactId ---
[INFO] Executing tasks
     [echo] Displaying value of 'my.group' property
     [echo] [my.group] group/test
     [echo] Displaying value of 'my.version' property
     [echo] [my.version] test

但是命令grep fileUri target\deployit-working-dir\deployit-manifest.xml显示Uri中的vars没有被替换:

代码语言:javascript
复制
grep fileUri target\deployit-working-dir\deployit-manifest.xml
      <fileUri>http://mynexus.ur/service/local/repositories/my-repo/content/${my.group}/anArtefact/${my.version}/anArtefact-1.0.zip</fileUri>

POM是以下文件:

代码语言:javascript
复制
<project xmlns="http://maven.apache.org/POM/4.0.0" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>myGroupId</groupId>
    <artifactId>myArtifactId</artifactId>
    <version>1.0</version>

    <packaging>dar</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <id>regex-properties</id>
                        <goals>
                            <goal>regex-properties</goal>
                        </goals>
                        <configuration>
                            <regexPropertySettings>
                                <regexPropertySetting>
                                    <name>my.group</name>
                                    <value>group/${tag}</value>
                                    <regex>(asm-[0-9]+)-([0-9]+.[0-9]+)-([0-9]+)$</regex>
                                    <replacement>$1</replacement>
                                    <failIfNoMatch>false</failIfNoMatch>
                                </regexPropertySetting>
                                <regexPropertySetting>
                                    <name>my.version</name>
                                    <value>${tag}</value>
                                    <regex>(asm-[0-9]+)-([0-9]+.[0-9]+)-([0-9]+)$</regex>
                                    <replacement>$1-SNAPSHOT</replacement>
                                    <failIfNoMatch>false</failIfNoMatch>
                                </regexPropertySetting>
                            </regexPropertySettings>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.1</version>
                <executions>
                    <execution>
                        <phase>validate</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <tasks>
                                <echo>Displaying value of 'my.group' property</echo>
                                <echo>[my.group] ${my.group}</echo>
                                <echo>Displaying value of 'my.version' property</echo>
                                <echo>[my.version] ${my.version}</echo>
                            </tasks>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.xebialabs.xldeploy</groupId>
                <artifactId>xldeploy-maven-plugin</artifactId>
                <version>6.0.0</version>

                <extensions>true</extensions>

                <configuration>
                    <deployables>
                        <file.Folder name="file">
                            <scanPlaceholders>false</scanPlaceholders>
                            <fileUri>http://mynexus.ur/service/local/repositories/my-repo/content/${my.group}/anArtefact/${my.version}/anArtefact-${project.version}.zip</fileUri>
                        </file.Folder>
                    </deployables>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

我不太确定build-helper-maven-plugin是否错误,或者我的POM中的其他地方,或者它是否只是缺少替换xldeploy-maven-plugin中的属性.

(谢谢你的帮助;)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-14 10:35:36

我检查了xldeploy plugin-6.0.1的源代码,这似乎是当前实现的限制。

问题是GenerateDeploymentPackageMojo不依赖于maven来进行属性的替换。相反,它使用名为AbstractConfigurationConverter的自定义DeployitCIConverter (委托给MavenDeployableConverter)将<deployables>节点转换为MavenDeployable列表)

这归结为:

  • 您可以使用有效的POM。
  • 您无法访问通过build插件动态定义的属性

当然,动态定义的属性可以在任何mojo中访问:

对于antrun插件,它在echo任务中明确使用ExpressionEvaluator。资讯文章:Maven中的属性解析及其对Antrun插件的影响

解决问题的思路:

  • 在外部脚本中执行组和版本解析,并将值传递给mvn命令。
  • 在execute方法中创建扩展GenerateDeploymentPackageMojo和预处理部署的cutom mojo (听起来并不难)。
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56570735

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档