271

How do you build a Maven project without running unit tests?

Currently restructuring some code I have for a Servlet and would like to try it out in my web browser (which means running mvn install to get the .war to upload to Tomcat). I'm fully aware my UNIT tests are failing and I'm fine with that because I will fix it once I have the code the way I want. Can anyone advise?

ljk
  • 488
  • 1
  • 5
  • 11
Federer
  • 33,677
  • 39
  • 93
  • 121

7 Answers7

489

If you want to skip running and compiling tests:

mvn -Dmaven.test.skip=true install

If you want to compile but not run tests:

mvn install -DskipTests
Mohammed H
  • 6,880
  • 16
  • 81
  • 127
alphazero
  • 27,094
  • 3
  • 30
  • 26
40

If you are using eclipse there is a "Skip Tests" checkbox on the configuration page.

Run configurations → Maven Build → New → Main tab → Skip Tests Snip from eclipse

Elazar
  • 20,415
  • 4
  • 46
  • 67
JStark
  • 2,788
  • 2
  • 29
  • 37
14

Run following command:

mvn clean install -DskipTests=true

PraAnj
  • 899
  • 1
  • 10
  • 27
OhadR
  • 8,276
  • 3
  • 47
  • 53
10

With Intellij Toggle Skip Test Mode can be used from Maven Projects tab:

Blue
  • 22,608
  • 7
  • 62
  • 92
Mujahid Masood
  • 111
  • 2
  • 8
4
mvn clean install -Dskiptests=true   

Now, the only difference from the answers above is that the "T" is in lower case.

Bw. Kizito
  • 68
  • 7
3

I like short version: mvn clean install -DskipTests

It's work too: mvn clean install -DskipTests=true

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

and you can add config in maven.xml

<project>
      [...]
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.16</version>
            <configuration>
              <skipTests>true</skipTests>
            </configuration>
          </plugin>
        </plugins>
      </build>
      [...]
    </project>
Gleb Belyaev
  • 1,009
  • 1
  • 14
  • 23
-3

If you call your classes tests Maven seems to run them automatically, at least they did for me. Rename the classes and Maven will just go through to verification without running them.