Gradle 1.0-m9: MapNotationParser removing keys from dependency definitions specified as Maps


(detelinyordanov) #1

Hi,

The ‘MapNotationParser’ in Gradle 1.0 milestone 9 is removing known dependency properties (group/name/version, etc.) from any dependency definition specified as a Map:

Map commonsLang = [ group: ‘commons-lang’, name: ‘commons-lang’, version: ‘2.6’ ]

dependencies {

compile (commonsLang)

}

//fails, key removed

assert commonsLang[‘group’]

The above worked with Gradle 1.0-m8.

Regards,

Detelin


(Luke Daley) #2

Thanks for the report, I’ve exported as GRADLE-2195.


(david koch) #3

In order to keep external dependencies consistent over several modules we maintain a global map with all external dependencies like that:

modules = [ <br />
 testNg: [group:'org&#46;testng', name:'testng', version: '6&#46;1'], <br />
 &#46;&#46;&#46; <br /> ] <br /> dependencies{ <br />
 testCompile(modules&#46;testNg) <br /> }


This works so far until Gradle 1.0-milestone-8a. With Gradle 1.0-milestone-9 our testNg dependency declaration map is emptied somewhere during the build and causes the build to fail.

In order to find the bug I just guarded this map with an asImmutable() method.

modules = [ <br />
 testNg: [group:'org&#46;testng', name:'testng', version: '6&#46;1']&#46;asImmutable(), <br />
 &#46;&#46;&#46; <br /> ]


This seems not to work at all because now there is an UnsupportedOperationException for all declared dependencies thrown by the MapNotationParser. You can check this out with the following simple build file:

apply plugin: 'java' <br /> dependencies{ <br />
 testCompile ([group:'org&#46;testng', name:'testng', version: '6&#46;1']&#46;asImmutable()) <br /> }



Even if the testNg dependency declaration is emptied somewhere in our build script (but it works with 8a) than it would be great if the dependency declaration could be made immutable in order to prevent accidental modifications.

This reply was created from a merged topic originally titled MapNotationParser seems to modify parameters map.


(Luke Daley) #4

This has been fixed for the upcoming release and is available in the nightlies.