我有下面的pom.xml。
我希望使用以下命令将一个tag属性传递给我的构建:
mvn clean package -Dtag=test
它应该将该属性拆分为另外两个属性,my.group和my.version,然后使用它在URI中使用xldeploy-maven-plugin (https://docs.xebialabs.com/xldeploy-maven-plugin/6.0.x/)构建XLDeploy包。
我的问题是,regex-properties的目标实际上就是完成这项工作,我可以看到,多亏了maven-antrun-plugin
[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没有被替换:
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是以下文件:
<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中的属性.
(谢谢你的帮助;)
发布于 2019-06-14 10:35:36
我检查了xldeploy plugin-6.0.1的源代码,这似乎是当前实现的限制。
问题是GenerateDeploymentPackageMojo不依赖于maven来进行属性的替换。相反,它使用名为AbstractConfigurationConverter的自定义DeployitCIConverter (委托给MavenDeployableConverter)将<deployables>节点转换为MavenDeployable列表)
这归结为:
当然,动态定义的属性可以在任何mojo中访问:
对于antrun插件,它在echo任务中明确使用ExpressionEvaluator。资讯文章:Maven中的属性解析及其对Antrun插件的影响
解决问题的思路:
GenerateDeploymentPackageMojo和预处理部署的cutom mojo (听起来并不难)。https://stackoverflow.com/questions/56570735
复制相似问题