Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using maven profiles to control build execution

Tags:

maven-2

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?

like image 589
Dean Schulze Avatar asked Jan 13 '11 20:01

Dean Schulze


People also ask

Why profiles are used 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).

How do I run a specific profile in Maven?

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 .

Which of the build profile is defined in Maven?

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.


1 Answers

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.

like image 119
Zac Thompson Avatar answered Sep 25 '22 11:09

Zac Thompson