Maven: Using a Plugin Based On Profile
Asked Answered
P

2

15

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>
Plemmons answered 30/1, 2012 at 12:38 Comment(0)
E
43

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.

Expire answered 30/1, 2012 at 17:37 Comment(0)
M
5

Using pluginManagement will not cause the build plugin to run. It is used to specify plugin version and configuration information to child POMs. Also you're missing the 'profile' child element of 'profiles'. Lastly, unless you plan on activating the profile via -P, you'll need some activation criteria.

May answered 30/1, 2012 at 16:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.