Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在pom中设置为不编译测试?_Java_Maven_Testing_Pom.xml - Fatal编程技术网

Java 如何在pom中设置为不编译测试?

Java 如何在pom中设置为不编译测试?,java,maven,testing,pom.xml,Java,Maven,Testing,Pom.xml,如何在pom中设置为不在Maven中编译测试?我试过: <properties> <skipTests>true</skipTests> </properties> 真的 但是在这种情况下,Maven编译测试,但不运行它们。我需要Maven不要编译我的测试。如果您使用surefire插件执行测试,您可以根据命名模式将其配置为跳过测试: <project> [...] <build> <plug

如何在pom中设置为不在Maven中编译测试?我试过:

<properties>
  <skipTests>true</skipTests>
</properties>

真的

但是在这种情况下,Maven编译测试,但不运行它们。我需要Maven不要编译我的测试。

如果您使用
surefire插件执行测试,您可以根据命名模式将其配置为跳过测试:

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.14</version>
        <configuration>
          <includes>
            <include>%regex[.*[Cat|Dog].*Test.*]</include>
          </includes>
        </configuration>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

[...]
org.apache.maven.plugins

在surefire插件上。您可能会发现更有用或更适合您的情况。

您必须定义maven.test.skip为true

<properties>
    <maven.test.skip>true</maven.test.skip>
</properties>

真的

配置maven编译器插件以跳过编译。 再一次,我不推荐它

<project>
  <properties>
    <maven.test.skip>true</maven.test.skip>
  </properties>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.0</version>
        <configuration>
        <executions>
          <execution>
            <id>default-testCompile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>testCompile</goal>
            </goals>
            <configuration>
              <skip>${maven.test.skip}</skip>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

真的
[...]
org.apache.maven.plugins
maven编译器插件
3
默认测试编译
测试编译
测试编译
${maven.test.skip}
[...]

在我的例子中,解决方案是将测试放在配置文件中(例如runTests),因此当我想要运行这些测试时,我添加参数
-PrunTests
。感谢您的回复。

也许您可以有一个指向测试源目录的配置文件。我不需要编译它们,因为这些测试调用Web服务,解析它的类等等。由于项目使用Hudson进行持续集成,我们只需要在明确设置这些测试时编译和运行它们。@Rafael。我认为这样做会破坏构建的可移植性。如果我以后需要激活测试编译和运行,mvn clean install-Dmaven.test.skip=false可以工作吗?或者我需要另一个参数?@Rafael。我想,您可以使用
maven.test.skip
来拉动一个双任务,这将跳过运行它们。OP想跳过compilation@user2863942引用我的链接:“如果您绝对必须这样做,您也可以使用maven.test.skip属性跳过编译测试。Surefire、Failsafe和编译器插件都支持maven.test.skip。”-Dmaven.test.skip=true只是为了方便复制/粘贴,您甚至不需要“=true”。通过设置它,它是真实的。