3

I am using maven 3.0.4 . I want the failsafe and jetty plugin to run (run only integration tests) only when I set some property in executing maven command for example mvn verify -Pstage -DrunIT=true

My stage profile in pom looks like this.

<profile>
        <id>stage</id>
        <activation>
            <activeByDefault>false</activeByDefault>

        </activation>
        <build>
            <plugins>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-failsafe-plugin</artifactId>
                    <version>2.16</version>
                    <executions>
                        <execution>
                            <id>integration-test</id>
                            <goals>
                                <goal>integration-test</goal>
                            </goals>
                        </execution>
                        <execution>
                            <id>verify</id>
                            <goals>
                                <goal>verify</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>


                <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>maven-jetty-plugin</artifactId>
                    <version>6.1.16</version>
                    <dependencies>
                        <dependency>
                            <groupId>javax.servlet</groupId>
                            <artifactId>servlet-api</artifactId>
                            <version>2.5</version>
                        </dependency>

                        <dependency>
                            <groupId>junit</groupId>
                            <artifactId>junit</artifactId>
                            <version>4.11</version>
                        </dependency>
                        <dependency>
                            <groupId>org.hamcrest</groupId>
                            <artifactId>hamcrest-all</artifactId>
                            <version>1.3</version>
                        </dependency>

                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>5.1.6</version>
                        </dependency>

                        <dependency>
                            <groupId>xmlunit</groupId>
                            <artifactId>xmlunit</artifactId>
                            <version>1.5</version>
                        </dependency>



                    </dependencies>
                    <configuration>
                        <scanIntervalSeconds>10</scanIntervalSeconds>
                        <stopPort>8005</stopPort>
                        <stopKey>STOP</stopKey>
                        <contextPath>/</contextPath>
                    </configuration>
                    <executions>
                        <execution>
                            <id>start-jetty</id>
                            <phase>pre-integration-test</phase>
                            <goals>
                                <goal>run-exploded</goal>
                            </goals>
                            <configuration>
                                <scanIntervalSeconds>0</scanIntervalSeconds>
                                <daemon>true</daemon>
                            </configuration>
                        </execution>
                        <execution>
                            <id>stop-jetty</id>
                            <phase>post-integration-test</phase>
                            <goals>
                                <goal>stop</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>


            </plugins>
        </build>
    </profile>
atul.mishra
  • 35
  • 1
  • 9
  • 1
    Why is a profile not enough? – khmarbaise Mar 05 '14 at 10:47
  • creating a new profile will require a lot a rework in my project. I need to find a way to activate or deactivate a plugin based on argument passed. Can I create a maven plugin which will somehow do so? – atul.mishra Mar 06 '14 at 03:59

1 Answers1

2

Well, in the <activation/> you need to define the property, which you seem to have missed:

...
<profile>
    <id>stage</id>
    <activation>
        <activeByDefault>false</activeByDefault>

        <property>
            <name>runIT</name>
            <!-- I think you can safely skip the value part below
                 and just pass in -DrunIT. -->
            <value>true</value>
        </property>
    </activation>
    ...
</profile>
carlspring
  • 31,231
  • 29
  • 115
  • 197
  • 1
    Thanks for your answer but this will activate or run the profile. With this mvn verify -Pstage will become same as mvn verify -DrunIT=true , but I want to activate or deactivate a plugin in a profile based on argument passed. So, mvn verify -Pstage -DrunIT=true will run stage profile with maven failsafe and maven jetty plugin and if runIT is set to false , both the plugins will not work. I cannot create a two different profiles , one will have the plugins and one will not. – atul.mishra Mar 06 '14 at 03:59