Unable to resolve class Map.Entry with gradle 2.12

We are trying out gradle 2.12 with our existing build and it appears to have an issue which doesn’t exist with the previous versions. I’ve been able to define a simple build.gradle file which reproduces the issue. This build file works perfectly fine with gradle 2.9 and 2.11 but with 2.12 the error message when processing the build.gradle is:

FAILURE: Build failed with an exception.

  • Where:
    Build file ‘***********/build.gradle’ line: 9

  • What went wrong:
    Could not compile build file ‘******/build.gradle’.

startup failed:
build file ‘***********/build.gradle’: 9: unable to resolve class Map.Entry
@ line 9, column 1.
for(Map.Entry entry : properties.entrySet()) {
^

1 error

The build.gradle contents:
apply plugin: ‘base’

Properties properties = new Properties()
File propertiesFile = new File(rootProject.projectDir, ‘gradle.properties’)
propertiesFile.withInputStream {
properties.load(it)
}

for(Map.Entry entry : properties.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
rootProject.ext.setProperty(key, value)
println “${key}=${value}”
}

And the gradle.properties in the same directory just has:
TEST_PROPERTY=value

With older releases of gradle the file works:

gradle build
TEST_PROPERTY=value
:assemble UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE

BUILD SUCCESSFUL

Total time: 3.335 secs

This appears to be a bug. I raised GRADLE-3423

This is enough to reproduce it: Map.Entry entry = null

As a workaround, you could import java.util.Map.Entry and then only use Entry (instead of Map.Entry) or just use def:

for(def entry : properties.entrySet())

or more Groovy-like (this is off the top of my head)…

properties.each { k,v ->
  rootProject.ext.setProperty(k, v)
  println "$k = $v"
}

There should be a fix for this coming in Gradle 2.13 (RC probably next week).

1 Like

Same issue here, as a workaround I’ll use a full qualified reference instead of an import:

def config = new Properties()
...
for (java.util.Map.Entry property in config) {
  ...
}