Gradle spring subprojects/multimodule

Hey,

I’m having the following module structure in my test gradle app:

root:

  • domain1
    • api
    • impl
  • domain2
    • api
    • impl
  • bootstrap

Problem happens when trying to import domain1:api into domain2:impl and domain2:api into domain1:impl. In domain2.impl interface and other classes from domain1.api cannot be found. In my repository there is Domain1Client that cannot be resolved. However, if in module2.impl build.gradle I switch:

 implementation project(':domain2:api')
 implementation project(':domain1:api')

to

 implementation project(':domain1:api')
 implementation project(':domain2:api')

then classes from domain1:api are resolved but classes domain2:api are not resolved.

Here is my settings.gradle:

rootProject.name = 'spring-gradle-multimodule-impl-api'
include 'domain1:api', 'domain2:api', 'domain1:impl', 'domain2:impl', 'bootstrap'

Here is my root build.gradle:

plugins {
    id 'java'
    id 'org.springframework.boot' version '2.7.4'
    id 'io.spring.dependency-management' version '1.0.14.RELEASE'
}

allprojects {
    apply plugin: 'java'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'

    repositories {
        mavenCentral()
    }

    bootJar {
        enabled = false
    }

    jar {
        enabled = true
    }
}

subprojects {
    apply plugin: 'java'
    apply plugin: 'org.springframework.boot'
    apply plugin: 'io.spring.dependency-management'

    group = 'me.kupchenko'
    version = '0.0.1-SNAPSHOT'
    sourceCompatibility = '1.8'

    configurations {
        compileOnly {
            extendsFrom annotationProcessor
        }
    }

    dependencies {
        implementation 'org.springframework.boot:spring-boot-starter-web'
        compileOnly 'org.projectlombok:lombok'
        annotationProcessor 'org.projectlombok:lombok'
        testImplementation 'org.springframework.boot:spring-boot-starter-test'
    }

    test {
        useJUnitPlatform()
    }

    bootJar {
        enabled = false
    }

    jar {
        enabled = true
    }
}

Here is my domain2.impl:

dependencies {
    implementation project(':domain2:api')
    implementation project(':domain1:api')
}

Here is the repository you can use to reproduce the issue:

@Vampire thank you very much!

There is indeed conflict.
(In case somebody needs the solution)
So what I did to solve this is renamed:

domain1:api -> domain1: domain1-api
domain1:impl -> domain1: domain1-impl
domain2:api -> domain2: domain2-api
domain2:impl -> domain2: domain2-impl
1 Like