How to find rootProject in Gradle 3.2.1

2.8k views Asked by At

atm I'm going through the gradle User-Guide at https://docs.gradle.org/current/userguide/multi_project_builds.html#sec:dependencies_which_dependencies

I just followed the instructions there and double-, triple- and quadruple-checked what I did, but for some reason I keep running into

 Could not set unknown property 'producerMessage' for root project 'messages' of type org.gradle.api.Project.

And I can't really figure out what the problem is (same goes for 2 colleagues).

Does someone have some experience here or just realized like "Ohyeah, the problem is ..." ??? Maybe I'm just too blind by now.

My question is basically how do I declare the property on rootProject and how come I can't find that step in the userguide?

settings.gradle

include 'consumer', 'producer'

consumer/build.gradle

task action {
doLast {
    println("Consuming message: ${rootProject.producerMessage}")
}}

producer/build.gradle

task action {
doLast {
    println "Producing message:"
    rootProject.producerMessage = 'Watch the order of execution.'
}}
1

There are 1 answers

2
Stanislav On BEST ANSWER

You have to declare a variable in the root project before you try to use it in subprojects. So you have to add build.gradle file in the folder with settings.gradle file and declare this variable within it for example as follows:

ext.producerMessage = null

It's just a problem with undeclared variable. You can take a look into the sources as well, to see, that it's declared. The problem is that user guide doesn't saym that you need to have one more file with the variable declaration.