我正在尝试使用现有库创建一个java项目,但我无法准确理解Composite Gradle Build的想法。我有一个 API 项目和一个 webServer 项目,我想将 API 类导入到 webServer 中。
这是api的gradle构建
plugins {
id 'java-library'
}
apply plugin: 'java'
apply plugin: 'application'
group = 'org.dkf.jed2k'
version = '2.0'
description = "jed2k core library"
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
repositories {
mavenCentral()
jcenter()
}
test {
useJUnit()
maxHeapSize = '1G'
}
dependencies {
api group: 'org.slf4j', name: 'slf4j-jdk14', version:'1.7.33'
implementation 'com.google.re2j:re2j:1.6'
implementation 'com.google.code.gson:gson:2.8.8'
implementation 'com.squareup.okhttp:okhttp:2.7.5'
testImplementation group: 'junit', name: 'junit', version:'4.13.2'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.0.111-beta'
}
这是 webServer 的 gradle 构建
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.4'
id 'io.spring.dependency-management' version '1.1.4'
}
group = 'org.dkf.jed2k'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
repositories {
mavenCentral();
}
dependencies {
implementation(":core")
//implementation files('/home/david/Documents/jed2k/core/build/libs/core-2.0.jar')
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
}
tasks.named('test') {
useJUnitPlatform()
}
bootRun {
systemProperties = System.properties
}
我已经按照指南组装了当前项目,但我仍然不明白如何将“org.dkf.jed2k”与我添加的额外文件夹集成,或者在命名它或将其添加到构建时是否有错误.
您想使用
composite build将
api
导入 webServer
。
为此,请将
api
添加为 webServer
的 settings.gradle
中的包含构建:
includeBuild '../api'
现在
api
的传出工件将可供webServer
使用。这意味着您可以添加以下行:
dependencies {
implementation 'org.dkf.jed2k:api:2.0'
}
和
api
的类应该在 webServer
的代码中可用。