Why does Maven launch the profile plugin, even if the profile is not activated

Another question is Maven. I have a TestNG test application running maven-surefire-plugin. I created 2 profiles, for pdoruction and for testing.

I create my application with the command "mvn clean install". Now my goal is to run TestNG tests only when I specify a test profile.

The 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 the tests run every time I create my application ... regardless of whether the "test" profile is specified or not. Why?

0
java maven
Dec 17 '15 at 12:09
source share
3 answers

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

  <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> 
+2
Dec 17 '15 at 12:16
source share

I think you should explicitly skip the tests.

Try adding the following configuration to your default profile.

 <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> 

Hope this helps.

+1
Dec 17 '15 at 12:16
source share

There is a solution to run tests ONLY if the maven "test" is activated:

 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> </plugins> </build> <profiles> <profile> <id>test</id> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>false</skipTests> </configuration> </plugin> </plugins> </build> </profile> </profiles> 

See also How to keep Maven profiles that are active ByDefault active even if another profile is activated?

0
Jan 23 '17 at 14:29
source share



All Articles