关于build.gradle:Gradle在SubProject中找不到类

Gradle can't find classes in SubProject

我想通过Gradle构建MultiProject。

RootBroject和SubProject的平面目录。我认为这很简单。
但是Gradle看起来在SubProject中找不到类。

在这种情况下我该怎么办?

项目目录类似于:

1
2
3
4
5
6
7
8
RootProject
+- build.gradle
+- settings.gradle
+- src
SubProject
+- src
+- build
 +- classes

和子项目版本:

1
gradlew :DataAccessProject:compileJava

BUILD SUCCESSFUL,我在SubProject / build / classes中找到了这些类
但是Sub RootProject Build:

1
gradlew :compileJava

BUILD FAILED,并且RootProject中的消息超过100,例如

1
2
import a.b.c.SomeClassOfSubProject;
            ^

settings.gradle:

1
2
3
rootProject.name = 'RootProject'

includeFlat 'SubProject'

build.gradle:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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??
}

我找不到明确的原因,
但是这个build.gradle到达了BUILD SUCCESSFUL

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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")
}

您是否已仔细检查代码中的所有包声明?