Why Maven runs profile plugin even if profile is not activated

Another Maven question. I have app with TestNG tests running by maven-surefire-plugin. I have created 2 profiles, for pdoruction and for testing.

I’m building my app by ‘mvn clean install’ command. Now my goal is to run TestNG tests only when I specify test profile.

Code:

profiles>
    <profile>
        <id>prod</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
    </profile>

    <profile>
        <id>test</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <version>2.19</version>
                    <configuration>
                        <suiteXmlFiles>
                            <suiteXmlFile>${basedir}/target/test-classes/firstTest.xml</suiteXmlFile>
                        </suiteXmlFiles>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

</profiles>

But the problem is that tests are running everytime when I build my app… no matter if ‘test’ profile is specified, or not. Why?

Answer

You can run mvn clean install -DskipTests or change your production profile definition:

 <profile>
     <id>prod</id>
     <activation>
         <activeByDefault>true</activeByDefault>
     </activation>
     <build>
         <plugins>
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
                 <version>2.19</version>
                 <configuration>
                     <skipTests>true</skipTests>
                 </configuration>
             </plugin>
         </plugins>
     </build>
 </profile>

Leave a Reply

Your email address will not be published. Required fields are marked *