Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: Using a Plugin Based On Profile

Tags:

maven

I have a file which maintains a build-number for release build. Everytime a release build is made, this number is incremented and the file is saved into svn repository.

Now say I have a plugin to do this job and i have created a build profile. But I need this plugin to be triggered only when build profile is activated and not otherwise. I guess adding pluginManagement to profile could be the way out like below. Any suggestions?

<profiles>
    <id>release</id>      
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    ..
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</profiles>
like image 801
Shagufta Avatar asked Jan 30 '12 12:01

Shagufta


People also ask

Why is the use of the profile required in Maven?

A profile in Maven is an alternative set of configuration values which set or override default values. Using a profile, you can customize a build for different environments. Profiles are configured in the pom. xml and are given an identifier.

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

I would suggest you take a look at the documentation for build profiles first. You can find that here. The first thing you want to look over is this section:

How can a profile be triggered? How does this vary according to the type of profile being used?

Basically, once you understand that, note that what you put in your profile section is pretty close to what you have outside your profile. That being said, if you need a profile specific build section, it should emulate what you would have outside the profile - if you take a look at the pom.xsd it is the exact same I believe.

So, for example:

<profiles>
    <profile>
        <id>full-build</id>
        <activation>
            <property>
                <name>build</name>
                <value>full</value>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo.webstart</groupId>
                    <artifactId>webstart-maven-plugin</artifactId>
                    <version>1.0-beta-1</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>jnlp</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <resourcesDirectory>src/main/web</resourcesDirectory>
                        ....

This would be triggered by running: mvn package -Dbuild=full

I hope this helps.

like image 58
javamonkey79 Avatar answered Sep 21 '22 18:09

javamonkey79