Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip execution of a plugin based on a property

Tags:

maven

In my Maven build I use maven-processor-plugin to generate JPA meta model like this

<plugin>
    <groupId>org.bsc.maven</groupId>
    <artifactId>maven-processor-plugin</artifactId>
    <version>2.2.4</version>
    <executions>
        <execution>
            <id>process</id>
            <goals>
                <goal>process</goal>
            </goals>
            <phase>generate-sources</phase>
            ....
        </execution>
</plugin>

Now I would like to skip the meta model generation based on a property, like this

$ mvn -Dspeed.up.build.from.eclipse=true

Unfortunately the maven-processor-plugin doesn't support <skip>${speed.up.build.from.eclipse}</skip> configuration tag like some plugins do.

I could put my plugin in a profile and then activate it based on my property. But then I need somehow to negate the value of the property...

So I need:

  • Execute plugin, if no property was set
  • Skip execution of the plugin, if the property was set

Is there some nice way to archieve it? If yes, how?

like image 738
Boris Brodski Avatar asked Jan 07 '16 19:01

Boris Brodski


2 Answers

Judging from the documentation, there is indeed no skip property.

In such a case, a possible solution is to use the hack of setting the phase to none to disable the plugin execution. You would define 2 profiles

  • one activated by the presence of the property speed.up.build.from.eclipse that would set a custom property maven-annotation-plugin.phase to none;
  • one activated by the absence of that property that would set this custom property to the actual phase you want the plugin to run.

You would then use the custom property as your phase in your plugin configuration.

Note that it is a hack because this is an undocumented feature.


Another solution (that I would recommend actually) would be to make a pull request adding that feature. The code is hosted on GitHub so you can easily fork it, patch it and make a pull request. In the mean time, you can use your custom plugin, and when the request is merged, you could drop your custom plugin.

like image 107
Tunaki Avatar answered Nov 03 '22 15:11

Tunaki


Had similar issue with a different plugin, I opted for the following solution:

<properties>
  <mvn.processor.goal>process</mvn.processor.goal>
</properties>

<plugin>
    <groupId>org.bsc.maven</groupId>
    <artifactId>maven-processor-plugin</artifactId>
    <version>2.2.4</version>
    <executions>
        <execution>
            <id>process</id>
            <goals>
                <goal>${mvn.processor.goal}</goal>
            </goals>
            <phase>generate-sources</phase>
            ....
        </execution>
</plugin>

Then when you run it you can do:

$ mvn -Dmvn.processor.goal=none
like image 1
abe Avatar answered Nov 03 '22 17:11

abe