我开发了一个带有@aggregator 注释的maven 插件。
如果我跑
mvn clean compile my:artifact:task package
然后编译 2 次。
所以我将这个片段插入我的pom
<plugin>
<groupId>my</groupId>
<artifactId>artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<executions>
<execution>
<id>post-classes</id>
<phase>process-classes</phase>
<goals>
<goal>task</goal>
</goals>
</execution>
</executions>
</plugin>
但随后它将在每个模块上运行(@aggregator 似乎被忽略)。
如何让插件编译后运行一次?
编辑: 我的问题是指 eclipse tycho 的默认生命周期。但是有一个 major bug所以我很困惑。
最佳答案
来自 this :
For mojos executed directly from the CLI, the mojo will only be executed once and not per each project in the reactor. For mojos bound to a lifecycle phase, the mojo will be executed for each project where the lifecycle binding is present.
你有两个选择:
如果您坚持使用聚合器注释:删除生命周期绑定(bind)并通过命令行运行它,例如“mvn clean compile my:artifact:task jar:jar”。类似于 assembly:assembly它旨在直接从命令行调用,并且永远不应绑定(bind)到构建生命周期阶段。
如果您坚持将插件绑定(bind)到生命周期,请删除聚合器注释并遵循此 article .这个想法是检查 Maven 当前正在运行的项目属性。
关于java - Maven类后处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15133609/