0

For example, I would like to exclude tests from build here:

task foo(dependsOn: ['clean', 'build']) {
    build.mustRunAfter clean
}

Instead of build I need build -x test.
How can I pass -x test to build in Groovy?

Nikola
  • 117
  • 7
  • 1
    Why not depend on something else instead of build? Gradle doesn't work the way you're trying to use it... If you only want compilation, then just depend on `assemble` https://docs.gradle.org/current/userguide/java_plugin.html#lifecycle_tasks – tim_yates Apr 24 '21 at 15:28
  • @tim_yates I need something that works exactly like `build` but without tests. `assemble` is different, see comments here: https://stackoverflow.com/a/4714118/5969852. – Nikola Apr 24 '21 at 15:31
  • Is it javadoc or compiling the test classes you'd miss? Why compile them if you don't run them? – tim_yates Apr 24 '21 at 16:15

1 Answers1

1

Start parameters like -x cannot be defined for single tasks. They are always part of a specific Gradle invocation.

You may however create a task that invokes Gradle from inside Gradle:

task foo(type: GradleBuild) {
    tasks = ['clean', 'build']
    startParameter.excludedTaskNames = ['test']
}
Lukas Körfer
  • 13,515
  • 7
  • 46
  • 62