如何为插件的不同执行提供不同的属性集?

时间:2018-09-24 11:22:50

标签: maven maven-3 maven-assembly-plugin

我正在使用def job = build job: 'say-hello', parameters: [[$class: 'StringParameterValue', name: 'who', value: 'DZone Readers']], wait: false 来组装不同的工件,如下所示:

maven-assembly-plugin

<build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>src/main/assembly/assembly.xml</descriptor> </descriptors> </configuration> <executions> <execution> <id>configuration-staging</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> <execution> <id>configuration-production</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> 中,我启用了模板过滤:

assembly.xml

这很好。例如,如果我在要汇编的资源之一中输入<fileSets> <fileSet> <filtered>true</filtered> ,则将其替换为项目的名称。我还可以在${name}中定义属性,这些属性将由插件替换。

现在,我想为pom.xml的每次执行使用不同的属性。例如,我想介绍一个maven-assembly-plugin,其中包含要在目标环境中使用的URL(在上面的示例中为${url}staging)。

这可能吗?怎么样?

2 个答案:

答案 0 :(得分:4)

显然,可以在maven-assembly-plugin中为每次执行传递不同的属性,如下所示:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <appendAssemblyId>false</appendAssemblyId>
                <descriptors>
                    <descriptor>src/main/assembly/assembly.xml</descriptor>
                </descriptors>
            </configuration>
            <executions>
                <execution>
                    <id>configuration-staging</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <finalName>staging</finalName>
                        <filters>
                            <filter>src/main/assembly/staging.properties</filter>
                        </filters>
                    </configuration>
                </execution>
                <execution>
                    <id>configuration-production</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <finalName>production</finalName>
                        <filters>
                            <filter>src/main/assembly/production.properties</filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>

尽管这不能回答一般性问题,但可以专门针对maven-assembly-plugin回答问题。

更多信息可以在https://maven.apache.org/plugins/maven-assembly-plugin/examples/single/filtering-some-distribution-files.html上找到。

答案 1 :(得分:0)

您可以尝试使用Maven插件属性

https://www.mojohaus.org/properties-maven-plugin/index.html

允许您从文件或URL中读取属性。

相关问题