我在Gradle包装器构建中遇到麻烦。我的IntelliJ IDEA能够解决依赖关系,但Gradle不能。
我有一个Gradle项目,其结构如下:
service
|__app-service (Spring Boot Application)
|__lib
|__common (Spring Boot Library Modules)
版本版本:5.4.1
------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------
Build time: 2019-04-26 08:14:42 UTC
Revision: 261d171646b36a6a28d5a19a69676cd098a4c19d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_212 (Oracle Corporation 25.212-b03)
OS: Linux 4.15.0-52-generic amd64
service / settings.gradle
rootProject.name = "projekt"
include 'lib:common'
include 'app-service'
service / app-service / build.gradle
应用服务通过将:lib:common
声明为依赖项来编译compile project(':lib:common')
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'org.springframework.boot' version '2.1.5.RELEASE'
id 'java'
id 'war'
}
apply plugin: 'io.spring.dependency-management'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
test {
useJUnitPlatform()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
compile('org.springframework.boot:spring-boot-starter-jetty')
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
compile project(':lib:common')
testCompile('org.springframework.boot:spring-boot-starter-test') {
exclude module: 'junit', group: 'junit'
}
testCompile "org.assertj:assertj-core:$assertjCoreVersion"
testCompile "org.mockito:mockito-all:$mockitoAllVersion"
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor('org.projectlombok:lombok')
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
service / lib / common / build.gradle
buildscript {
ext {
junitPlatformVersion = '1.5.0-M1'
}
}
plugins {
id("org.springframework.boot") version '2.1.4.RELEASE'
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'io.spring.dependency-management'
jar {
version = '0.0.1-SNAPSHOT'
}
sourceCompatibility = 1.8
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
test {
useJUnitPlatform()
}
bootJar { enabled = false }
dependencies {
compile 'org.springframework.boot:spring-boot-starter'
compile 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testCompile('org.springframework.boot:spring-boot-starter-test') {
exclude module: 'junit'
}
testCompile 'org.springframework.boot:spring-boot-test-autoconfigure'
testCompile 'org.assertj:assertj-core'
testCompileOnly 'org.projectlombok:lombok'
testAnnotationProcessor('org.projectlombok:lombok')
testCompile('org.junit.jupiter:junit-jupiter-api')
testRuntimeOnly('org.junit.jupiter:junit-jupiter-engine')
}
在IntelliJ IDEA中,account-service
可以解析lib:common
的所有类,但是./gradlew build
不能。
例如:
symbol: class UserId
location: class UserRepositoryImpl
..../UserRepositoryImpl.java:28: error: cannot find symbol