I have a multi-project build. Sub-projects are in tree structure (not flat). In root build.gradle file I have a method that does some common thing for compilation phase.
I would like to have separate target dir for each subproject. So when I'm compiling whole project I will have own artifacts for each subproject. Method I mentioned above does compilation, so it needs to know which project it compiles.
If I use "gradle :subproject1:subsubproject1:compile" command then project.name still contains root project name. But I need in runtime to know project of task that called for method.
Questions are:
If the task is defined in the subproject then you can simply use project.name
to get the name of the project the task is run under.
You can try it out, for example by adding the following code to build.gradle located on the root project:
allprojects {
task printProjName << {
println ">> " + project.name
}
}
Then, executing the printProjName task will result in an output similar to the one below:
:printProjName
>> Gradle
:projA:printProjName
>> projA
:projB:printProjName
>> projB
:projA:projA1:printProjName
>> projA1
:projA:projA2:printProjName
>> projA2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With