Hey, I'm talking about profiles within pom.xml of a project. Could please anybody explain to me, why if I have 2 profiles in pom definition and I run test phase from one of the profiles, both the Main method is executed and all the tests are run by surefire plugin ? I mean, even the surefire plugin runs all the tests, even though it is within a different profile ?
mvn test -Pcode-generator
the first one,code-generator, is just for Main methods execution and the second one for the rest of the project.
<profiles>
<profile>
<id>code-generator</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>cz.instance.transl.Main</mainClass>
<arguments>
<argument>arg0</argument>
<argument>arg1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>default</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<warName>${war.file.name}</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7</version>
<configuration>
<useFile>false</useFile>
<argLine>-Dportal.test=generic
-Dwebdriver.chrome.driver="/opt/google/chrome/chromedriver"
-Dwebdriver.development=true
-Dwebdriver.firefox.useExisting=true
-Dwebdriver.firefox.profile=webdriver
-Dwebdriver.reap_profile=true
-Dsurefire.useFile=false
-Xmx2048M
-XX:MaxPermSize=1048M
-XX:+CMSClassUnloadingEnabled
</argLine>
<skipTests>false</skipTests>
<suiteXmlFiles>
<suiteXmlFile>${basedir}/src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemProperties>
<property>
<name>log4j.configuration</name>
<value>META-INF/log4j.xml</value>
</property>
</systemProperties>
<includes>
<include>cz/instance/transl/tests/selenium/*Test.java</include>
</includes>
<excludes>
<exclude>cz/instance/transl/tests/sample/*Test.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.7.1</version>
<!-- <configuration> <useFile>false</useFile> </configuration> -->
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/java</directory>
<includes>
开发者_StackOverflow中文版 <include>**/*.*</include>
</includes>
</testResource>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
<includes>
<include>**/*</include>
</includes>
</testResource>
</testResources>
<resources>
<resource>
<directory>${project.basedir}/src/main/java</directory>
<includes>
<include>**/*.java</include>
<include>service.properties</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
<include>profiles/*</include>
</includes>
</resource>
</resources>
</build>
</profile>
</profiles>
The surefire plugin is one that runs by default for a java project. You have a number of options:
- Add the surefire plugin to your
code-generator
profile and override it not to run. - Run with
-DskipTests
. - Specify only the goal you want to run, instead of running a full maven build.
精彩评论