I’m struggling with a problem with Gradle composite build. I have 2 separate gradle builds - project1 and project2. In first project (project2) all dependencies are defined in a separate file, which is applied inside project2/build.gradle, e.g.:
project2-dependencies.gradle
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation project(':module1')
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
I use that file also inside second project (project1) - it is assigned using gradle.includedBuild
:
apply from: file("${gradle.includedBuild('project2').projectDir}/module-specific-dependencies.gradle")
now, if I’m trying to run project2 it works fine, but for project1 I receive below error:
Project with path ':module1' could not be found in root project 'project1'.
I tried to change project2 dependency to:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'com.examplemod2:module1:0.0.1-SNAPSHOT'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
after that change problem was fixed - I was able to run project1, but below problem occurred during launching project2:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Could not find com.examplemod2:module1:0.0.1-SNAPSHOT.
Required by:
project :
only below solution worked for me:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation project.findProject(':module1') != null ? project.findProject(':module1') : 'com.examplemod2:module1:0.0.1-SNAPSHOT'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
but it seems to be too big workaround - how in this case I can use project dependency, assuming that project structure cannot be changed (dependencies have to be defined inside separate file)?
I created example project with this problem: link