我下面有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/ )。
我的问题是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中的var没有被替换:
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
中的属性...
感谢您的帮助;)
答案 0 :(得分:1)
我检查了xldeploy-maven-plugin-6.0.1的来源,看来这是当前实现的局限性。
问题在于GenerateDeploymentPackageMojo
不依赖Maven进行属性替换。相反,它使用名为AbstractConfigurationConverter
(代表DeployitCIConverter
的自定义MavenDeployableConverter
(将<deployables>
节点转换为MavenDeployable
的列表)
这可以归结为:
当然,可以在任何mojo中使用动态定义的属性:
对于antrun插件,它在echo任务中显式使用ExpressionEvaluator
。
信息文章:
Properties resolution in Maven and its implications on Antrun plugin
解决此问题的想法:
GenerateDeploymentPackageMojo
的纯文字mojo并在execute方法中预处理可部署对象(听起来并不那么困难)。