Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven: skip test-compile in the life cycle?

I have project that I set to build with the test-jar and normal jar by using this setting:

        <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-jar-plugin</artifactId>             <executions>                 <execution>                     <goals>                         <goal>test-jar</goal>                     </goals>                 </execution>             </executions>         </plugin> 

The problem with this is whenever I upgrade the project version in the pom, I need to do a build with the tests, otherwise maven won't be able to find the test-jar with the correct version during the test-compile phrase. A lot of time I would just want to skip the tests, but due to the test-jar missing, the test-compilephrase will fail.

I tried to use -Dmaven.test.skip=true, but that doesn't seem to skip the test-compile phase. Is there a way to skip this?

like image 780
fei Avatar asked Apr 26 '11 00:04

fei


People also ask

How do I skip a test in Maven?

To skip running the tests for a particular project, set the skipTests property to true. You can also skip the tests via the command line by executing the following command: mvn install -DskipTests.

Does mvn test compile?

mvn test-compile: Compiles the test source code. mvn test: Runs tests for the project. mvn package: Creates JAR or WAR file for the project to convert it into a distributable format. mvn install: Deploys the packaged JAR/ WAR file to the local repository.

How can you override skipTests parameter in command line?

Skipping by default by initializing the skipTests element value to true in properties and then overriding it through the command line by mentioning the value of -DskipTests in the maven phase/build execution command.


2 Answers

$ mvn clean install -Dmaven.test.skip=true \       -Dmaven.site.skip=true -Dmaven.javadoc.skip=true 
like image 199
gavenkoa Avatar answered Oct 08 '22 04:10

gavenkoa


If you want to skip the compilation of test sources, you can try configuring the maven compiler plugin suitably. This is not recommended though.

        <plugin>             <groupId>org.apache.maven.plugins</groupId>             <artifactId>maven-compiler-plugin</artifactId>             <version>2.3.2</version>             <executions>                 <execution>                     <id>default-testCompile</id>                     <phase>test-compile</phase>                     <goals>                         <goal>testCompile</goal>                     </goals>                     <configuration>                         <skip>true</skip>                     </configuration>                 </execution>             </executions>         </plugin> 
like image 37
Raghuram Avatar answered Oct 08 '22 03:10

Raghuram