Maven - Skip building test classes

非 Y 不嫁゛ 提交于 2019-12-03 03:25:32

问题


Is there a simple way to not build the test classes?

mvn clean install -Dmaven.test.skip=true

Walter


回答1:


According to the documentation on the Maven Surefire Plugin, -Dmaven.test.skip should skip both compilation and execution of the tests. By contrast, -DskipTests just skips the test execution: the tests are still compiled.




回答2:


Just to be explicitly clear:

skipTests will compile anything in the <testSourceDirectory>, but will not execute them.

maven.test.skip will NOT compile any tests, but WILL execute any compiled tests that made their way into the <testOutputDirectory>.

So the behavior of the above 2 is opposite. Just wanted to point out that maven.test.skip doesn't skip compilation AND execution if test files are unpacked/copied/etc. into <testOutputDirectory>.

Also, depending on which version of Maven your using, there's also maven.test.skip.exec=true which additionally skips test execution similar to skipTests.




回答3:


Run a phase that doesn't include test-compile, for example compile.

mvn clean compile



回答4:


I'm not an expert at maven, but what I use in my current project is:

mvn clean install -DskipTests=true

Depending on your use case using:

mvn compile -DskipTests=true

might work for you too.




回答5:


I found a work-around in another question, which actually overrides a plugin execution by adding the following snippet in your pom.xml by default:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <executions>
        <execution>
          <id>default-testCompile</id>
          <phase>none</phase>
        </execution>
      </executions>
   </plugin>
  </plugins>
</build>

This seems to work but definitely does not disable phase but disables the default actions that a plugin defines at a specific phase.



来源:https://stackoverflow.com/questions/2593588/maven-skip-building-test-classes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!