41

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?

markdsievers
  • 7,151
  • 11
  • 51
  • 83
fei
  • 2,224
  • 9
  • 31
  • 36

5 Answers5

78
$ mvn clean install -Dmaven.test.skip=true \
      -Dmaven.site.skip=true -Dmaven.javadoc.skip=true
gavenkoa
  • 45,285
  • 19
  • 251
  • 303
47

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>
Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • 2
    I'm actually looking for a command line param if that's possible. – fei Apr 26 '11 at 07:42
  • 14
    @fei. As specified in http://maven.apache.org/general.html#skip-test, `maven.test.skip=true` skips test compilation and execution. If this is not happening, you can update your question with log. – Raghuram Apr 26 '11 at 08:38
  • I had set my ID to something other than `default-testCompile` and this wouldn't work correctly. Why is this specific ID required? – Ungeheuer Feb 17 '20 at 22:31
  • 2
    @Ungeheuer you're trying to override the definition of an execution that's already defined for maven-compiler-plugin. The way I do that is `default-testCompile`, which unbinds it from any phase so it doesn't even show up as skipped. I use this in some projects to override various check-related plugins defined in parent-POMs for the default build profile. – MithrilTuxedo Apr 02 '20 at 20:29
11

Little Late, But to summarise in short and be precise -

Adding to what @Sridhar and @FWDekker said,

mvn clean install -DskipTests=true will just skip the Tests Execution

mvn clean install -Dmaven.test.skip will skip both compilation and execution of Tests.

SaratBhaswanth
  • 340
  • 7
  • 18
5

Just Add -Dmaven.test.skip . It will Not even compile test

kartick shaw
  • 915
  • 13
  • 5
  • Yes with this Test will not run but test files would compile . but giving only this would not compile the test files – kartick shaw Apr 02 '19 at 17:19
3

Here is my working command from https://maven.apache.org/plugins-archives/maven-surefire-plugin-2.12.4/examples/skipping-test.html

You can skip running tests with the following command

mvn clean install -DskipTests

If you absolutely must, you can also use the maven.test.skip property to skip compiling the tests. maven.test.skip is honored by Surefire, Failsafe and the Compiler Plugin.

mvn clean install -Dmaven.test.skip=true -DskipTests

Parisana Ng
  • 487
  • 4
  • 14