使用buildhelpermaven插件

使用buildhelpermaven插件,maven,xl-deploy,build-helper-maven-plugin,Maven,Xl Deploy,Build Helper Maven Plugin,我有下面的pom.xml 我想使用以下命令将标记属性传递给我的构建: mvn清洁包装-Dtag=test 它应该将此属性拆分为另外两个属性,my.groupanmy.version,然后在URI中使用它,使用XLDeploy maven插件构建XLDeploy包 我的问题是,regex属性目标实际上完成了这项工作,正如我所看到的,多亏了maven-antrun插件: [INFO] --- maven-antrun-plugin:1.1:run (default) @ myArtifactId -

我有下面的pom.xml

我想使用以下命令将
标记
属性传递给我的构建:

mvn清洁包装-Dtag=test

它应该将此属性拆分为另外两个属性,
my.group
an
my.version
,然后在URI中使用它,使用
XLDeploy maven插件构建XLDeploy包

我的问题是,
regex属性
目标实际上完成了这项工作,正如我所看到的,多亏了
maven-antrun插件

[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中的变量没有被替换:

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>
grep fileUri target\deployit working dir\deployit-manifest.xml
http://mynexus.ur/service/local/repositories/my-repo/content/${my.group}/anArtefact/${my.version}/anArtefact-1.0.zip
POM是以下文件:

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

4.0.0
myGroupId
myArtifactId
1
达尔
org.codehaus.mojo
构建助手maven插件
3.0.0
正则表达式属性
正则表达式属性
我的团队
组/${tag}
(asm-[0-9]+)-([0-9]+。[0-9]+)-([0-9]+)$
$1
错误的
我的版本
${tag}
(asm-[0-9]+)-([0-9]+。[0-9]+)-([0-9]+)$
$1-快照
错误的
org.apache.maven.plugins
maven antrun插件
1.1
验证
跑
显示“my.group”属性的值
[my.group]${my.group}
显示“my.version”属性的值
[my.version]${my.version}
com.xebialabs.xldeploy
xldeploymaven插件
6.0.0
符合事实的
错误的
http://mynexus.ur/service/local/repositories/my-repo/content/${my.group}/anArtefact/${my.version}/anArtefact-${project.version}.zip
我不太确定
构建助手maven插件
是否错误,或者我的POM中的其他地方是否错误,或者它是否只是缺少替换
xldeploy maven插件
中的属性


谢谢你的帮助;)

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

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

这归结为:

  • 您可以访问有效的POM
  • 您无法访问通过build helper插件动态定义的属性
当然,动态定义的属性可以在任何mojo中访问:

  • 如果使用参数
  • 如果通过表达式计算器手动计算它们(选中:)
对于antrun插件,它在echo任务中明确使用了
ExpressionEvaluator
。 资料性文章:

解决问题的方法:

  • 在外部脚本中执行组和版本解析,并将值传递给mvn命令
  • 创建一个cutom mojo扩展
    GenerateDeploymentPackageMojo
    并在execute方法中预处理可部署项(不像听起来那么难)

非常感谢您的详细准确回答;)不幸的是,我没有能够成功地编写一个新的mojo扩展GenerateDeploymentPackageMojo,我觉得没有源代码,作为maven插件中的noob没有帮助。。。我稍后再试。事实上,我也没有资源,但是IDE最近做得很好