In a multi-project setup, executing gradle tasks
does not list rules from subprojects.
Example setup:
rootProj/
build.gradle
settings.gradle
subProj/
build.gradle
where rootProj/build.gradle
-file:
tasks.addRule("Pattern: rootRule<Anything>") { String taskName ->
if(taskName.startsWith("rootRule")) {
task(taskName) << {
def anything = (taskName - "rootRule");
doLast {
println "Exec rootRule with ${anything}"
}
}
}
}
rootProj/settings.gradle
-file:
include 'subProj'
subProj/build.gradle
-file:
tasks.addRule("Pattern: subRule<Anything>") { String taskName ->
if(taskName.startsWith("subRule")) {
task(taskName) << {
def anything = (taskName - "subRule");
doLast {
println "Exec subRule with ${anything}"
}
}
}
}
This leads to the following output:
rootProj$ gradle tasks
:tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Help tasks
----------
components - Displays the components produced by root project 'multi-gradle-proj'. [incubating]
dependencies - Displays all dependencies declared in root project 'multi-gradle-proj'.
dependencyInsight - Displays the insight into a specific dependency in root project 'multi-gradle-proj'.
help - Displays a help message.
model - Displays the configuration model of root project 'multi-gradle-proj'. [incubating]
projects - Displays the sub-projects of root project 'multi-gradle-proj'.
properties - Displays the properties of root project 'multi-gradle-proj'.
tasks - Displays the tasks runnable from root project 'multi-gradle-proj' (some of the displayed tasks may belong to subprojects).
Rules
-----
Pattern: rootRule<Anything>
To see all tasks and more detail, run gradle tasks --all
To see more detail about a task, run gradle help --task <task>
BUILD SUCCESSFUL
Total time: 0.82 secs
-> The rootRule
is there, but the subRule
is missing from the output. Even though I can execute it from the root.
rootProj$ gradle subRuleTest
subProj:subRuleTest
Exec subRule with Test
BUILD SUCCESSFUL
Total time: 0.769 secs
-> doing gradle tasks
from the subProj
-Dir shows the rule correctly:
rootProj/subProj$ gradle tasks
:subProj:tasks
------------------------------------------------------------
All tasks runnable from project :sub1
------------------------------------------------------------
Help tasks
----------
components - Displays the components produced by project ':sub1'. [incubating]
dependencies - Displays all dependencies declared in project ':sub1'.
dependencyInsight - Displays the insight into a specific dependency in project ':sub1'.
help - Displays a help message.
model - Displays the configuration model of project ':sub1'. [incubating]
projects - Displays the sub-projects of project ':sub1'.
properties - Displays the properties of project ':sub1'.
tasks - Displays the tasks runnable from project ':sub1'.
Rules
-----
Pattern: subRule<Anything>
To see all tasks and more detail, run gradle tasks --all
To see more detail about a task, run gradle help --task <task>
BUILD SUCCESSFUL
Total time: 0.758 secs
=> gradle tasks
in the root project should also show rules from subprojects.