Parent project is not evaluated with "Configuration on demand" and partial build

I’ve noticed behavior which I consider to be incorrect in partial multi-module build.

Let’s say I have module structure like following:

group1
  sub11
  sub12
group2
  sub21
  sub22	

sub22 depends on sub11 and when building it ‘wants’ to save meta-information of the sub11 parent module ‘group1’ somewhere.

The problem is that

  • at build time it takes group1.version during packaging in group2:sub22:jar task

    tasks.jar.doFirst {
    println “{project(':group1')} version = {project(’:group1’).version}”
    }

  • but version is being dynamically calculated at project evaluation time, dummy code like following in root build .gradle

      gradle.beforeProject { project ->
      	project.version = project.version + '-' + project.name
      	println 'beforeProject: ' + project + ' -> ' + project.version
      	project.apply plugin: 'java'
      }
    

… and without evaluation of the group1 project actual result in project.version is '0.0.1' without suffix '-group1'. '0.0.1' is received from gradle.properties in root project.

I think parent projects should also be implicitly evaluated when dependency evaluation triggers evaluation of some child project.

Test project is attached
gradle-no-parent-eval.zip (6.1 KB)

Execution of gradle build in group2/sub22 generates following console output:

C:\Temp\gradle-test\group2\sub22>gradle build
Configuration on demand is an incubating feature.
beforeProject: project ':group2:sub22' -> 0.0.1-sub22
beforeProject: project ':group1:sub11' -> 0.0.1-sub11
:group1:sub11:compileJava UP-TO-DATE
:group1:sub11:processResources UP-TO-DATE
:group1:sub11:classes UP-TO-DATE
:group1:sub11:jar
:group2:sub22:compileJava UP-TO-DATE
:group2:sub22:processResources UP-TO-DATE
:group2:sub22:classes UP-TO-DATE
:group2:sub22:jar
project ':group1' version = 0.0.1
:group2:sub22:assemble
:group2:sub22:compileTestJava UP-TO-DATE
:group2:sub22:processTestResources UP-TO-DATE
:group2:sub22:testClasses UP-TO-DATE
:group2:sub22:test UP-TO-DATE
:group2:sub22:check UP-TO-DATE
:group2:sub22:build

BUILD SUCCESSFUL

Total time: 0.954 secs

Problem is in-place in recent Gradle v 2.11-rc-1

Hi,

This was a conscious design decision, which we potentially could still change given that --configure-on-demand is still incubating.

You should be able to get the behaviour you want by something like this:

gradle.beforeProject { project ->
  if (project != project.rootProject && project.parent != project.rootProject) {
    project.evaluationDependsOn(project.parentProject.path)
  }
}

This workaround seems to be working. Thanks.

Can you explain the reason behind ‘not evaluating parent automatically’?