Could not get unknown property '...' for configuration container error occurs depending on project name

Hi guys,

I created a simple task in one subproject where I print dependencies of some configuration from other project. In some cases this leads to an error: Could not get unknown property ‘compile’ for configuration container. I found out that the first project name affects to the error occurrence.


Project structure:
/
| - build.gradle
| - build-jar.gradle
| - build-ear.gradle
| - settings.gradle

Files content:

  • build.gradle

task wrapper(type: Wrapper) {
gradleVersion = “2.14.1”
}

  • build-jar.gradle

project(":jar") {
apply plugin: ‘java’

repositories {
    mavenCentral()
}

dependencies {
    compile 'commons-lang:commons-lang:2.4'
}

}

  • build-ear.gradle

project(’:ear’) {
task customTask() {
println ‘>>>’ + project(’:jar’).configurations.compile.dependencies
}
}

  • settings.gradle

include ‘:jar’, ‘:ear’
project(’:jar’).buildFileName = "…/build-jar.gradle"
project(’:ear’).buildFileName = “…/build-ear.gradle”

If you try to execute ‘clean’ task, you will get the error. But if the ‘ear’ project name will be changed to ‘tear’ as example in build-ear.gradle and settings.gradle files the error disappear.
build_files.zip (945 Bytes)


Gradle: 2.13 and 2.14.1
JVM: 1.8.0_31 (Oracle Corporation 25.31-b07)
OS: Windows 7 6.1 amd64

Hi,

your custom task actually prints out the compile time dependencies at configuration time. What you actually want to do is something like

task customTask() {
  doLast {
    println '>>>' + project(':jar').configurations.compile.dependencies
  }
}

The effect you are seeing is that the projects - if there is not dependency between them - are evaluated alphabetically.

I also do not understand why you have a project(...) block in build-jar.gradle and build-ear.gradle. It works the same way without that. This is only necessary if you include the configuration of the ear and jar project in the top level build.gradle.

Hi,

Thank you very much for your explanation.
I’ve just started to use Gradle and a lot of things I do doesn’t make any sense.