I have created a gradle project named my-root-project
, under which there are two other gradle projects: shared
and my-service
.
In my IntelliJ IDE, I have added shared
and my-service
as modules of my-root-project
. The project structure overall looks like this:
-my-root-project
-shared
-build.gradle
-settings.gradle
-my-service
-build.gradle
-settings.gradle
-build.gradle
-settings.gradle
...
In the settings.gradle
of my-root-project
I have:
rootProject.name = 'my-root-project'
include ':shared'
include ':my-service'
In build.gradle
of my-service
, I would like to add shared
as its project dependency:
...
dependencies {
implementation project(':shared')
}
But I get error:
A problem occurred evaluating root project 'my-service'.
> Project with path ':shared' could not be found in root project 'my-service'.
Then, I tried including shared
also in the settings.gradle
of my-service
. (Above, I have already included it in settings.gradle
of my-root-project
).
Then, build again but get a new error:
Could not resolve project :shared.
Required by:
project :
Possible solution:
- Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html
Where am I wrong? I would like to have shared
project be a dependency in my-service
.
It sounds like you’re running your Gradle command from within the my-service
project directory. As that project contains a settings.gradle
file, Gradle considers the project to be the root project. Under this “root project”, there is no subproject called shared
, so Gradle complains with the error you saw:
A problem occurred evaluating root project 'my-service'.
> Project with path ':shared' could not be found in root project 'my-service'.
I’d recommend to change two things (but either of them should get you rid of the error):
settings.gradle
file in a multi-project build – in the root project, i.e., your my-root-project
. If you look at the Gradle docs for multi-project builds, then you’ll see that there is only a single settings.gradle
file in each sample project hierarchy../gradlew :my-service:check
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With