Can sections 41.2 and 41.3 of the User’s guide be combined? In other words, I want to externally define some tasks, and then apply them in the parent project, with all the subprojects having access to them. Something like this:
External file (rpm_defaults.gradle):
println "configuring $project" task hiya << { task -> println 'hiya from rpm_defaults in $project'}
Base directory build.gradle:
subprojects { apply from: '../../rpm_defaults/rpm_defaults.gradle' }
Base directory settings.gradle
include 'p1','p2','p3'
result:
$ gradle -q hiya configuring project ':p1' configuring project ':p2' configuring project ':p3' hiya from rpm_defaults in $project hiya from rpm_defaults in $project hiya from rpm_defaults in $project
As a newbie I’m trying to wrap my head around the idea that the name of a subproject could be known at configuration time and seemingly “forgotten” when the task runs. Is the $notation something that is only known at config time?
I want those project references to be filled out at run time as they are at configure time. How can this be done?
Update:
Ok, this is really weird. If I change rpm_defaults.gradle as follows from the content shown above, to:
projectName=$project println "configuring " + projectName task hiya << { task -> println 'hiya from rpm_defaults in ' + projectName}
then I get an error:
$ gradle clean hiya
FAILURE: Build failed with an exception.
Where:
Script '/home/sc1478/rpm_defaults/rpm_defaults.gradle' line: 1
What went wrong:
A problem occurred evaluating script.
Could not find property '$project' on project ':p1'.
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Now this really makes no sense to my poor newby brain.
With the line
println "configuring $project"
gradle has no difficult handling $project
but with the line
projectName=$project
$project is unknown and produces an error.
I’m totally confused. Help!