Rafael Toledo
Rafael Toledo

Reputation: 5649

How do I set in the pom to not compile tests?

How do I set in the pom to not compile tests in Maven? I've tried:

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

but in that case, Maven compile the tests but don't run them. I need Maven don't compile my tests.

Upvotes: 8

Views: 4949

Answers (4)

stackh34p
stackh34p

Reputation: 9009

If you are using the surefire-plugin for executing tests, you can configure it to skip them based on a naming pattern:

<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>

This, however, requires the tests file names to conform to the desired pattern(s). At work we are using this approach, and have our tests end with ..UnitTest or ..IntegrationTest, so that we can easily turn each of them off by modifying the regex in the corresponding build profile.

Take a look at Apache's documentation on the surefire plugin. You may find something more useful or better suited for your case.

Upvotes: 0

Rafael Toledo
Rafael Toledo

Reputation: 5649

In my case a solution was to put tests in a profile (e.g. runTests), so when I want to run these tests, I add the parameter -PrunTests. Thanks for the replies.

Upvotes: 1

Alexander Pogrebnyak
Alexander Pogrebnyak

Reputation: 45576

Configure maven-compiler-plugin to skip the compilation. Once again, I do not recommend it.

<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>

Upvotes: 0

maba
maba

Reputation: 48055

You have to define maven.test.skip to true.

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

http://maven.apache.org/surefire/maven-surefire-plugin/examples/skipping-test.html

Upvotes: 8

Related Questions