如何为插件的不同执行提供不同的属性集?
How to provide different set of properties to the different executions of a plugin?
我正在使用 maven-assembly-plugin
到 assemble 不同的工件,如下所示:
<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>
效果很好。例如,如果我在要 assembled 的其中一个资源中输入 ${name}
,则将其替换为项目名称。我还可以在 pom.xml
中定义属性,它将被插件替换。
现在,我想为 maven-assembly-plugin
的每次执行设置不同的属性。例如,我想引入一个 ${url}
,它包含要在目标环境中使用的 URL(上例中的 staging
和 production
)。
这可能吗?怎么样?
您可以尝试使用属性 Maven 插件
https://www.mojohaus.org/properties-maven-plugin/index.html
允许您从文件或 URL 中读取属性。
显然,可以在 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 上找到更多内容。
我正在使用 maven-assembly-plugin
到 assemble 不同的工件,如下所示:
<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>
效果很好。例如,如果我在要 assembled 的其中一个资源中输入 ${name}
,则将其替换为项目名称。我还可以在 pom.xml
中定义属性,它将被插件替换。
现在,我想为 maven-assembly-plugin
的每次执行设置不同的属性。例如,我想引入一个 ${url}
,它包含要在目标环境中使用的 URL(上例中的 staging
和 production
)。
这可能吗?怎么样?
您可以尝试使用属性 Maven 插件
https://www.mojohaus.org/properties-maven-plugin/index.html
允许您从文件或 URL 中读取属性。
显然,可以在 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 上找到更多内容。