Spring Boot Multi Module Gradle Project 类路径问题:Package Not Found, Symbol not Found
Posted
技术标签:
【中文标题】Spring Boot Multi Module Gradle Project 类路径问题:Package Not Found, Symbol not Found【英文标题】:Spring Boot Multi Module Gradle Project classpath problem: Package Not Found, Symbol not Found 【发布时间】:2020-09-24 22:04:57 【问题描述】:我有一个 Spring Boot gradle 项目 etl
,它依赖于另一个名为 common
的项目中的公共核心类。
common/build.gradle
plugins
id 'net.ltgt.apt' version '0.21'
id 'org.springframework.boot'
id 'io.spring.dependency-management'
id "io.freefair.lombok" version "5.1.0"
id 'java'
id 'idea'
id 'eclipse'
group = 'com.intelease'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories
jcenter()
mavenCentral()
maven
name "lightbend-maven-release"
url "https://repo.lightbend.com/lightbend/maven-releases"
maven
name "Sonatype Snapshots"
url "https://oss.sonatype.org/content/repositories/snapshots/"
ivy
name "lightbend-ivy-release"
url "https://repo.lightbend.com/lightbend/ivy-releases"
layout "ivy"
dependencies
implementation 'com.typesafe.play:play-java_2.13:2.7.3'
implementation 'com.typesafe.akka:akka-actor-typed_2.13:2.5.23'
implementation "com.typesafe.play:play-guice_2.12:2.6.15"
implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb-reactive'
implementation 'org.neo4j.driver:neo4j-java-driver:1.7.5'
implementation 'org.apache.poi:poi-ooxml:3.17'
implementation 'com.google.maps:google-maps-services:0.13.0'
implementation 'org.apache.commons:commons-text:1.8'
implementation 'com.google.cloud:google-cloud-language:1.19.0'
implementation 'com.google.cloud:google-cloud-vision:1.19.0'
implementation 'technology.tabula:tabula:1.0.2'
implementation 'com.amazonaws:aws-java-sdk:1.11.618'
implementation 'edu.stanford.nlp:stanford-corenlp:3.8.0'
implementation 'nz.ac.waikato.cms.weka:weka-stable:3.8.4'
// https://mvnrepository.com/artifact/com.typesafe.play/play-java
implementation 'org.joda:joda-money:0.11'
implementation 'com.feth:play-easymail_2.12:0.9.0'
implementation 'com.feth:play-authenticate_2.12:0.9.0'
implementation 'org.apache.commons:commons-imaging:1.0-alpha1'
implementation 'com.github.cloudyrock.mongock:mongock-core:3.3.2'
implementation 'com.github.cloudyrock.mongock:mongock-spring:3.3.2'
implementation 'net.logstash.logback:logstash-logback-encoder:5.3'
implementation 'ch.qos.logback:logback-core:1.2.3'
implementation 'ch.qos.logback:logback-classic:1.2.3'
implementation 'com.google.firebase:firebase-admin:6.13.0'
implementation 'org.mapstruct:mapstruct:1.3.1.Final'
implementation 'org.jgrapht:jgrapht-core:1.4.0'
implementation 'org.jgrapht:jgrapht-io:1.4.0'
implementation 'commons-io:commons-io:2.6'
implementation 'org.springframework.guice:spring-guice:1.1.4.RELEASE'
implementation 'com.google.inject:guice:4.2.3'
implementation 'commons-collections:commons-collections:3.2.2'
implementation 'org.aspectj:aspectjrt:1.9.5'
implementation 'org.ghost4j:ghost4j:1.0.1'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
testAnnotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final' // if you are using mapstruct in test code
testImplementation 'io.projectreactor:reactor-test:3.3.0.RELEASE'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.2.0.RELEASE'
testImplementation 'cloud.localstack:localstack-utils:0.1.22'
testImplementation 'nl.jqno.equalsverifier:equalsverifier:3.3'
testImplementation 'net.aichler:jupiter-interface:0.8.3'
testImplementation 'org.mockito:mockito-junit-jupiter:3.0.0'
testImplementation 'org.assertj:assertj-core:3.13.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.5.2'
etl/settings.gradle:
rootProject.name = 'etl'
includeFlat ('common')
etl/build.gradle:
plugins
id 'org.springframework.boot' version '2.2.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'eclipse'
id 'idea'
id 'java'
group = 'com.intelease'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
repositories
mavenCentral()
jcenter()
maven
name "lightbend-maven-release"
url "https://repo.lightbend.com/lightbend/maven-releases"
ivy
name "lightbend-ivy-release"
url "https://repo.lightbend.com/lightbend/ivy-releases"
layout "ivy"
ext
set('springCloudVersion', "Hoxton.SR4")
dependencies
implementation project(':common')
implementation 'org.apache.kafka:kafka-streams'
implementation 'io.debezium:debezium-core:1.1.1.Final'
implementation 'org.springframework.cloud:spring-cloud-stream'
implementation 'org.springframework.cloud:spring-cloud-stream-binder-kafka-streams'
testImplementation('org.springframework.boot:spring-boot-starter-test')
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
testImplementation 'org.springframework.cloud:spring-cloud-stream-test-support'
dependencyManagement
imports
mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
test
useJUnitPlatform()
etl
项目和common
项目在文件系统的同一级别中并排。
问题是,每当我尝试构建依赖于common
的etl
项目时,它都会显示一些关于我希望从common
项目中获得并可用的类的问题。
我已使用includeFlat
将common
包含在etl
项目中的settings.gradle
中,并且无法追踪有关gradle 多模块包含机制的任何问题。
这个扁平的多模块生态系统有什么问题?
构建脚本是 etl 文件夹中的./gradlew clean build
。
【问题讨论】:
【参考方案1】:问题是因为 etl
和 common
项目中都存在 spring boot 插件。所以我发现在cammon/build.gradle
我必须添加这段代码:
...
bootJar
enabled = false
jar
enabled = true
...
【讨论】:
以上是关于Spring Boot Multi Module Gradle Project 类路径问题:Package Not Found, Symbol not Found的主要内容,如果未能解决你的问题,请参考以下文章
Spring Boot Multi Module Gradle Project 类路径问题:Package Not Found, Symbol not Found
无法集成测试 gradle 多模块 Spring-Boot-Application
带有 OAuth 的 Spring Boot Security Multi Http 不起作用