I’d like to `includeBuild()` and set a property on...
# community-support
j
I’d like to
includeBuild()
and set a property on the included build, as if I were invoking it with
-Dfoo=bar
. The best I can come up with is to write some code that edits the included build’s
gradle.properties
before I include it. Got a better way?
(My included build is set up to omit some optional modules by default, but I absolutely need 'em in from the calling build, so I was hoping to request it that way)
j
Yes exchanging information "in-memory" between two builds during the initialization phase (when the
includes
are evaluated) is not really possible as far as I know. So I think you need to do it via file system, as with your
gradle.properties
idea. If you want to have it more hidden, you can configure the second build to read information/properties from some other file of your choice (for example one you put inside
build
or
.gradle
).
Although as you mention
-D
... ....maybe you can use Java System pProperties as all this code runs in the same Daemon JVM. It may be possible to do
System.setProperty("foo", "bar")
in the first build and later retrieve it in the second build. Don't know if it works, and if it would be smart. Changing the state of the daemon is not recommended as it will also affect the follow up builds running on it. If it works, you should reset the property after reading it.
j
ooooh this is helpful
Yeah I think this confirms my guess, that
gradle.properties
is bad, and the other options are not better
Opened a feature request here: https://github.com/gradle/gradle/issues/31638
v
Why not just set the
systemProp...
via the
gradle.properties
of the including build?