'Gradle add library depencecy in a project without break the build.gradle multi-project definition on the root path
I am new with gradle and I don't know how to resolve this issue. I have two gradle projects structured as follow:
./api
/build.gradle.kts
/settings.gradle.kts
./util
/build.gradle.kts
/settings.gradle.kts
./build.gradle.kts
./settings.gradle.kts
where substantially:
- 'api' project has its build.gradle and settings.gradle
- 'util' project the same and build.gradle and setting.gradle
- the root are used to build all these projects in one shot
in addition:
- 'api' is a library (let me say as just a common library with utils and api interface and so on)
- 'util' must be depends from api (internally 'util' need to refer pacakges of api as 'import se.magnus.api' and so on)
Now my problem is: how can add 'api' project in the 'util' as dependency for use all the classes insiede of packages 'se.magnus.api' without break the build.gradle and setting.gradle on the root?
In fact if I add try to add project 'api' to 'util' as depedency:
[./util/setting.gradle.kts]
rootProject.name = "util"
include(":api")
project(":api").projectDir = file("../api")
[./util/build.gradle.kts]
implementation(project(":api"))
and try to build, I receive this error:
Error resolving plugin [id: 'io.spring.dependency-management', version: '1.0.11.RELEASE'] > Plugin request for plugin already on the classpath must not include a version
refer to 'plugin' section on the './api/build.gradle' file:
plugins {
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.6.10"
}
because seems that no plugin section with version already exist. If I remove the version of build.gradle 'api' project then 'util' works fine and I see the classes under the packages of common library added as dependency BUT if I try to run 'build.gradle' on the root to compile all the project and try to run 'build.gradle' on the 'api' project I receive the following error (for both projects!):
FAILURE: Build failed with an exception.
* Where:
Build file 'C:\Users\apieri\STS4\workspace\Poc\spring-demo\api\build.gradle.kts' line: 3
* What went wrong:
Plugin [id: 'io.spring.dependency-management'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Now the question is: how can resolve this? how can add dependency on 'util' project of a common library and see the classes importing packages without break the compilation of all projects included in the build.gradle root?
Many thanks for any help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
