I want to execute gradle build
without executing the unit tests. I tried:
$ gradle -Dskip.tests build
That doesn\'t seem to
gradle build -x test --parallel
If your machine has multiple cores. However, it is not recommended to use parallel clean.
You will have to add -x test
e.g. ./gradlew build -x test
or
gradle build -x test
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.
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
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