How to know invoked project on a multi-project partial build?

(Raul Piaggio) #1

We have a multi-project build.

Usually, we do partial builds, invoking gradle from one of the subrpojects.

Except for project-specific configurations, all our build logic is in the master project. Is there a way to know from there which project was gradle invoked from?

Example: We have projects A, B, C and master. We invoke gradle from project A. master’s project build.gradle is executed. We would like to identify from there that project A is where gradle was invoked from.

(Matias Bjarland) #2

I am assuming that you use either the allprojects {} or the subprojects{} construct in your master build.gradle?

If so, the tasks invoked in those closures run in the context of the calling project. In other words, if you put:

println "OUTSIDE PATH: ${gradle.startParameter.currentDir}"
  allprojects {
  task whoami << {
    println "---------------"
    println "PATH: ${project.path}"
    println "DIR:

in your root project build.gradle and go into one of your subprojects and run “gradle whoami”, it will print out the subproject project path and project dir in the whoami task. Also, if you need to get hold of the calling project location outside of any tasks, the startParameter invocation above might be a solution.

(Raul Piaggio) #3

Thank you Matias!

The startParameter.currentDir is exactly what I was looking for. I can compare it to projectDir in subprojects{} and know if I am configuring the invoked project or not.