Search code examples
gradlebuild.gradlegradlewmulti-project

Gradle can't find classes in SubProject


I'd like to build MultiProject by Gradle.

Flat directories of RootBroject and SubProject. I think it's simple. But Gradle looks like can't find classes in SubProject.

How can I do that in this case?

Project dirs are like:

RootProject
+- build.gradle
+- settings.gradle
+- src
SubProject
+- src
+- build
 +- classes

And SubProject Build:

gradlew :DataAccessProject:compileJava

was BUILD SUCCESSFUL and I found the classes in SubProject/build/classes But Sub+RootProject Build:

gradlew :compileJava

was BUILD FAILED and the Messages are more than 100 in RootProject like

import a.b.c.SomeClassOfSubProject;
            ^

settings.gradle:

rootProject.name = 'RootProject'

includeFlat 'SubProject'

build.gradle:

buildscript {
    ext {
        springBootVersion = '2.0.6.RELEASE'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("org.springframework:springloaded:1.2.1.RELEASE")
        classpath("io.spring.gradle:dependency-management-plugin:0.6.1.RELEASE")
    }
}

allprojects {

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

    group = 'abc'
    sourceCompatibility = 11
    targetCompatibility = 11

    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }

    dependencies {

        implementation('org.springframework.boot:spring-boot-starter-jdbc')
        implementation('org.projectlombok:lombok:1.18.4')

        implementation fileTree(dir: 'lib', include: ['*.jar'])
    }
}

project(':SubProject') {
}

dependencies {
    implementation('org.springframework.boot:spring-boot-starter-web')
    implementation('org.springframework.boot:spring-boot-starter-thymeleaf')

    implementation project(':SubProject') // Can't find classes in SubProject??
}

Solution

  • I can't find the cause cleary, But this build.gradle got to BUILD SUCCESSFUL.

    buildscript {
        ext {
            springBootVersion = "2.1.1.RELEASE"
        }
        repositories {
            mavenCentral()
            maven {
                url "https://plugins.gradle.org/m2/"
            }
        }
        dependencies {
            classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        }
    }
    
    allprojects {
        apply plugin: "java"
        apply plugin: "io.spring.dependency-management"
    
        [compileJava, compileTestJava]*.options*.encoding = "UTF-8"
    
        repositories {
            mavenCentral()
        }
    
        dependencyManagement {
            imports {
                mavenBom "org.springframework.boot:spring-boot-dependencies:$springBootVersion"
            }
        }
    
        sourceCompatibility = 11
        targetCompatibility = 11
    
        dependencies {
            implementation("org.springframework.boot:spring-boot-starter-security")
            implementation("org.modelmapper.extensions:modelmapper-spring:2.3.0")
            ...
    
            compileOnly("org.projectlombok:lombok:1.18.4")
            annotationProcessor("org.projectlombok:lombok:1.18.4")
    
            testImplementation("org.springframework.boot:spring-boot-starter-test")
            testImplementation("org.springframework.security:spring-security-test:5.1.1.RELEASE")
            ...
        }
    }
    
    project(":SubProject") {
    
        dependencies {
            implementation("org.mybatis.spring.boot:mybatis-spring-boot-starter:1.3.2")
            ...
        }
    }
    
    
    apply plugin: "org.springframework.boot"
    apply plugin: "war"
    
    dependencies {
        implementation project(":SubProject")
        implementation("org.springframework.boot:spring-boot-starter-web")
        implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
    
        providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
    }