I need to modify the maven build for a large project to skip certain steps during typical development builds (i.e. don't build the *-source.jar files). I've searched for "conditional execution" for maven, but haven't found anything.
A dev profile sounds like the intuitive way to do this - but I don't know how intuitive maven is. The docs for profiles show how to set different properties (i.e. database connection parameters) for different profiles. I suppose I could set a property and then test if that property is set in the maven-source-plugin - executions - execution tag.
Is this the right way to do conditional execution in maven?
What's the "right" way to do this in maven?
Profiles modify the POM at build time, and are used to give parameters different target environments (for example, the path of the database server in the development, testing, and production environments).
What you should do is check the profile behavior by doing the following : set activeByDefault to true in the profile configuration, run mvn help:active-profiles (to make sure it is effectively activated even without -Pdev1 ), run mvn install .
A - A Build profile is a set of configuration values which can be used to set or override default values of Maven build. B - Using a build profile, you can customize build for different environments such as Production v/s Development environments.
You're thinking about it a bit backwards: have the profile enable the behaviour, not disable it. This is just what profiles are best at, and is exactly your case: you only want the steps to be run in certain circumstances. So you might have something like:
<profile> <id>source-jars</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> ...
And in fact there's an example just like this on the maven-source-plugin usage page. When you need to generates your artifact, use mvn -P source-jars (or whatever). That's it! If you only need to do this at release time, the release plugin even offers a way to define the profiles to use right in the release plugin configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With