Boris Brodski
Boris Brodski

Reputation: 8715

Skip execution of a plugin based on a property

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:

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

Upvotes: 6

Views: 9188

Answers (2)

abe
abe

Reputation: 341

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

Upvotes: 3

Tunaki
Tunaki

Reputation: 137289

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

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.

Upvotes: 6

Related Questions