简体   繁体   中英

Maven class post-processing

I developed a maven plugin with @aggregator annotation.

If I run

mvn clean compile my:artifact:task package

then it compiles 2 times.

So I insert this fragment into my 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>

but then it will run on each module (@ aggregator is seemingly ignored).

How do I let the plugin run once after compiling?

Edit: My problem refers to the default lifecycle of eclipse tycho. But there is an major bug so I was very confused.

From 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.

You have two options:

  • If you insist on using the aggregator annotation: remove the lifecycle binding and run it via command line, such as "mvn clean compile my:artifact:task jar:jar". Similar to assembly:assembly which is designed to be invoked directly from the command line, and should never be bound to a build lifecycle phase.

  • If you insist on binding your plugin to lifecycle, remove the aggregator annotation and follow this article . The idea is to examine the project properties where maven is currently running on.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM