Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

conditionally execute maven plugins

Tags:

java

maven-2

I have some Maven plugins configured in my pom.xml. I only want to execute these plugins if the tests are being run (tests may be skipped using either -Dmaven.test.skip=true or -DskipTests).

One of these plugins is bound to the process-classes build lifecycle phase and the other is bound to the pre-integration-test phase.

like image 887
Dónal Avatar asked Mar 26 '11 14:03

Dónal


People also ask

What is the correct syntax for executing a maven plugin?

Usage of a Maven Plugin xml you can use the shorthand notation to execute the plugin: mvn <prefix>:<goal> , commonly the “prefix” is the artifact ID minus the “-maven-plugin”. For example mvn example:version .

What is the difference between plugin and pluginManagement tags?

pluginManagement: is an element that is seen along side plugins. Plugin Management contains plugin elements in much the same way, except that rather than configuring plugin information for this particular project build, it is intended to configure project builds that inherit from this one.

How do I use maven plugins?

In Maven, there are two kinds of plugins, build and reporting: Build plugins are executed during the build and configured in the <build/> element. Reporting plugins are executed during the site generation and configured in the <reporting/> element.


1 Answers

You can use profile with special activation conditions like this:

<project>   ...   <profiles>     <profile>       <id>my-test-plugins</id>        <activation>         <property><name>!maven.test.skip</name></property>         <property><name>!skipTests</name></property>       </activation>       <build>         <plugins>        <!-- define your plugins here -->          </plugins>       </build>     </profile>   </profiles> </project> 

More info you can find here:

http://books.sonatype.com/mvnref-book/reference/profiles-sect-activation.html

like image 116
tenshi Avatar answered Sep 23 '22 13:09

tenshi