Extra properties in m9 read only in settings.gradle?

Context: I have some code which builds up a multi-project structure. The code is called from settings.gradle. Part of the code needs to export custom properties both to the settings.gradle file (i.e. the code after the call which sets the properties should be able to access it) and to gradle build files.

This used to work by just using the “this” pointer available in the settings context (some mix between Script and Settings I assume) and setting properties on that.

With m9 however, running code like the following in settings.gradle:

ext.properties['foo'] = 'bar'
  println "The value of foo is ${foo}"

results in:

FAILURE: Build failed with an exception.
  * Where:
Settings file '/Users/mbjarland/tmp/extra_properties/settings.gradle' line: 3
  * What went wrong:
A problem occurred evaluating settings 'extra_properties'.
> Could not find property 'foo' on settings 'extra_properties'.
  * Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
  BUILD FAILED

How should I go about modifying the extra properties in settings.gradle?

The suggested syntax is…

ext.foo = “bar”

If you need a version that uses strings, it’s…

ext.set(“foo”, “bar”)

Not supporting the syntax you are using was a conscious decision. It somewhat clashes with Groovy semantics which could have unpredictable side effects, so we didn’t support it.

Thank you for the fast answer.

I managed to get confused by the fact that you can do ext.properties to iterate over the properties and assumed the properties property would work for setting also.

That solved the problem and the string version was exactly what I was looking for. Thanks again, excellent support as usual.