maven - 根据配置文件属性条件执行maven插件
问题描述
给定 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>
只有当属性等于时,我才能执行send-file
任务?我知道我可以在该示例中将标签移至和配置文件,但我需要为每个配置文件复制该部分,这似乎不是一个好的解决方案。在我的情况下,我定义了更多配置文件并且插件执行定义更长,它会使我的 pom 文件变得很混乱,并且使任何更改都非常容易出错。是否有任何条件标签可以传递给执行,让我决定是否调用它?或者也许有可能通过配置文件标签中的 id 排除执行?env
prod
plugin
dev-a
prod-a
感谢帮助!
解决方案
如果my-plugin
真的是你的插件(即你写的),最简单的事情就是在插件中实现你想要的逻辑。
推荐阅读
- docker - 超级账本浏览器是实时的吗?
- validation - 如何对 .net 核心 Web API 请求进行模型验证?
- mysql - MySQL COUNT 查询没有响应
- postgresql - 错误:绑定消息有 9914 个参数格式但有 0 个参数
- java - 我无法生成 gRPC 存根类
- react-native - Expo显示剩余音频秒数
- javascript - 显示所选图像或名称的标签 (javascript)
- ruby - 在字符串Ruby中查找单词“The”之后的所有单词
- angularjs - 如何在angularJS 1.6X中引用另一个指令
- sql - 从数据库中获取每周记录