我是 Gradle 的新手,正在努力构建一个 https://docs.gradle.org/current/samples/sample_building_java_applications_multi_project.html。
我正在尝试与此处提到的相同:https://stackoverflow.com/questions/20008324/gradle-multiple-jars-from-single-source-folder/20010200#20010200
我有三个包,依赖是:PandaService
=> PandaServiceDataAccessLayer
=> PandaDatabaseDocker
。
现在我想为 PandaService
构建一个胖罐子。但是,我无法获得 ./gradlew build
工作。现在它抱怨 Plugin with id 'org.springframework.boot' not found.
我该如何解决?
还将感谢有关更改 build.gradle
以遵循最佳实践的任何建议。
更多信息
这是 PandaService
的 settings.gradle
:
rootProject.name = "PandaService"
include "PandaService"
include "PandaDatabaseDocker"
include "PandaServiceDataAccessLayer"
这是 PandaService
的 build.gradle
:
subprojects {
apply plugin: 'java'
}
project(':PandaDatabaseDocker') {
sourceSets {
main {
java {
srcDir '../src'
include 'PandaDatabaseDocker/**'
}
}
}
}
project(':PandaServiceDataAccessLayer') {
sourceSets {
main {
java {
srcDir '../src'
include 'PandaServiceDataAccessLayer/**'
}
}
}
dependencies {
implementation project(':PandaDatabaseDocker')
}
}
project(':PandaService') {
repositories {
mavenCentral()
}
group = 'PandaService'
version = '0.0.1'
sourceCompatibility = '11'
targetCompatibility = '11'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
sourceSets {
main {
java {
srcDir '../src'
include 'PandaService/**'
}
}
}
dependencies {
// Add depended local modules
implementation project(':PandaServiceDataAccessLayer')
// Spring boot + Jersey
implementation 'org.springframework.boot:spring-boot-starter-parent:2.6.4'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-jersey'
compileOnly("org.springframework.boot:spring-boot-devtools")
testImplementation 'org.springframework.boot:spring-boot-starter-test'
// Swagger
implementation 'io.swagger:swagger-jersey2-jaxrs:1.6.5'
// Lombok
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
// log
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
// RDS Connection
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
runtimeOnly 'mysql:mysql-connector-java:8.0.27'
// AWS secretes manager
implementation 'com.amazonaws.secretsmanager:aws-secretsmanager-jdbc:1.0.6'
// JOOQ
implementation 'org.springframework.boot:spring-boot-starter-jooq'
// HikariCP
implementation 'com.zaxxer:HikariCP:5.0.1'
}
//create a fat Jar with all dependencies
jar {
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
dependsOn configurations.runtimeClasspath
from {
configurations.compileClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
attributes "Main-Class": "com.PandaService.MainApplication"
}
}
configurations {
all*.exclude module: 'spring-boot-starter-logging'
all*.exclude module: "logback-classic"
compileOnly {
extendsFrom annotationProcessor
}
}
test {
useJUnitPlatform()
}
}
回答1
我整理了一下。
解决方案是使用 Gradle 复合构建。这样,我什至不需要包装根项目。
参考:
- https://blog.jetbrains.com/idea/2016/10/intellij-idea-2016-3-eap-gradle-composite-builds-and-android-studio-2-2/
- https://stackoverflow.com/questions/60464719/gradle-includebuild-vs-implementation-project
- https://docs.gradle.org/3.1/release-notes.html#composite-builds
- https://stackoverflow.com/questions/60464719/gradle-includebuild-vs-implementation-project
- https://blog.jetbrains.com/idea/2017/03/webinar-recording-composite-builds-with-gradle/
- https://docs.gradle.org/current/userguide/composite_builds.html#defining_composite_builds