Question

I want to execute gradle build without executing the unit tests. I tried:

$ gradle -Dskip.tests build

That doesn't seem to do anything. Is there some other command I could use?

Was it helpful?

Solution

You should use the -x command line argument which excludes any task.

Try:

gradle build -x test 

Update:

The link in Peter's comment changed. Here is the diagram from the Gradle user's guide

OTHER TIPS

Try:

gradle assemble

To list all available tasks for your project, try:

gradle tasks

UPDATE:

This may not seem the most correct answer at first, but read carefully gradle tasks output or docs.

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.

The accepted answer is the correct one.

OTOH, the way I previously solved this was to add the following to all projects:

test.onlyIf { ! Boolean.getBoolean('skip.tests') }

Run the build with -Dskip.tests=true and all test tasks will be skipped.

You can add the following lines to build.gradle, **/* excludes all the tests.

test {
    exclude '**/*'
}

Reference

To exclude any task from gradle use -x command-line option. See the below example

task compile << {
    println 'task compile'
}

task compileTest(dependsOn: compile) << {
    println 'compile test'
}

task runningTest(dependsOn: compileTest) << {
    println 'running test'
}
task dist(dependsOn:[runningTest, compileTest, compile]) << {
    println 'running distribution job'
}

Output of: gradle -q dist -x runningTest

task compile
compile test
running distribution job

Hope this would give you the basic

the different way to disable test tasks in the project is:

tasks.withType(Test) {enabled = false}

this behavior needed sometimes if you want to disable tests in one of a project(or the group of projects).

This way working for the all kind of test task, not just a java 'tests'. Also, this way is safe. Here's what I mean let's say: you have a set of projects in different languages: if we try to add this kind of record in main build.gradle:

 subprojects{
 .......
 tests.enabled=false
 .......
}

we will fail in a project when if we have no task called tests

gradle build -x test --parallel

If your machine has multiple cores. However, it is not recommended to use parallel clean.

Please try this:

gradlew -DskipTests=true build

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top