Reputation: 97
How do I configure subprojects for Gradle and run a Gradle task from the build.gradle
only for the current directory I'm executing the task from?
For example, suppose I have two projects in a parent folder:
root-project
project-1
project-2
build.gradle
settings.gradle
I have project 1 and 2 included in the settings.gradle
file:
include(
'project-1',
'project-2'
)
I have a task configured in the build.gradle
file that I would like to call. I've nested the tasks within a subprojects{}
block:
subprojects {
...
task check(type: JavaExec) {
main = MAIN_CLASS
classpath = sourceSets.main.runtimeClasspath
}
...
}
However, the build.gradle
is run for all subprojects that way.
How can I define all possible subprojects but only call a Gradle task for the current project I'm executing from (i.e., avoid calling the task for all subprojects)? I would like to do this with the current task name only (e.g., gradle check
).
Upvotes: 1
Views: 5943
Reputation: 14500
Invoking the task in a single project with gradle check
is not possible.
You have two options:
gradle :project-1:check
or gradle :project-2:check
depending on which task you want to run.gradle check1
or gradle check2
Upvotes: 1