【发布时间】:2020-06-03 12:12:15
【问题描述】:
给定 pom.xml
<plugin>
<groupId>com.myplugin</groupId>
<artifactId>my-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<id>generate-file</id>
<phase>package</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<templateFile>
${project.build.directory}/template.json
</templateFile>
<outputFile>
${project.build.directory}/${env}-${server}-file.json
</outputFile>
</configuration>
</execution>
<execution>
<id>send-file</id>
<phase>package</phase>
<goals>
<goal>send</goal>
</goals>
<configuration>
<file>
${project.build.directory}/${env}-${server}-file.json
</file>
</configuration>
</execution>
</executions>
</plugin>
<profiles>
<profile>
<id>dev-a</id>
<properties>
<env>test</env>
<server>serverA</server>
</properties>
</profile>
<profile>
<id>prod-a</id>
<properties>
<env>prod</env>
<server>serverA</server>
</properties>
</profile>
<profile>
<id>dev-b</id>
<properties>
<env>test</env>
<server>serverB</server>
</properties>
</profile>
<profile>
<id>prod-b</id>
<properties>
<env>prod</env>
<server>serverB</server>
</properties>
</profile>
</profiles>
只有当env 属性等于prod 时,我才能执行send-file 任务?我知道在该示例中我可以将plugin 标签移动到dev-a 和prod-a 配置文件,但我需要为每个配置文件复制该部分,这似乎不是一个好的解决方案。在我的情况下,我定义了更多配置文件并且插件执行定义更长,它会使我的 pom 文件混乱很多并且使任何更改都非常容易出错。
是否有任何条件标签可以传递给执行,让我决定是否调用它?或者是否有可能通过配置文件标签中的 id 排除执行?
感谢您的帮助!
【问题讨论】:
-
@KarthikeyanVaithilingam 不,不是真的。正如我在问题中所推理的那样,他们正在描述一种我想避免的方法。我需要为大多数配置文件执行相同的插件,但不是全部,我不想只复制文件的一部分。
-
看来这个插件不适合使用...这应该由插件处理,而不是通过配置文件等。