gradle多模块项目打包依赖拆分
作者:互联网
一、目录结构
.
├── boogle-common
│ ├── build.gradle.kts
│ └── src
├── boogle-core
│ ├── build.gradle.kts
│ └── src
├── boogle-generator
│ ├── build.gradle.kts
│ └── src
├── boogle-logging
│ ├── build.gradle.kts
│ └── src
├── boogle-quartz
│ ├── build.gradle.kts
│ └── src
├── boogle-system
│ ├── build.gradle.kts
│ └── src
├── boogle-web-starter
│ ├── build.gradle.kts
│ └── src
├── buildSrc
│ ├── build
│ ├── build.gradle.kts
│ └── src
│ └── main
│ └── kotlin
│ └── org.wm.java-conventions.gradle.kts
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle.kts
二、buildSrc/src/main/kotlin/org.wm.java-conventions.gradle.kts配置
/*
* This file was generated by the Gradle 'init' task.
*/
plugins {
`java-library`
`maven-publish`
id("org.springframework.boot")
}
apply(plugin = "io.spring.dependency-management")
tasks.named<org.springframework.boot.gradle.tasks.bundling.BootJar>("bootJar") {
mainClass.set("com.xqx.ApplicationRun")
}
repositories {
mavenLocal()
flatDir {
dirs("lib")
}
maven {
url = uri("https://maven.aliyun.com/repository/public/")
}
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
maven {
url = uri("https://repo.jenkins-ci.org/releases")
}
maven {
url = uri("https://repo.maven.apache.org/maven2/")
}
}
dependencies {
...
}
group = "com.xqx"
version = "2022.05.09"
java.sourceCompatibility = JavaVersion.VERSION_17
publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
}
}
tasks.withType<JavaCompile>() {
options.encoding = "UTF-8"
}
三、boogle-web-starter/build.gradle.kts配置(入口模块)
plugins {
id("com.xqx.java-conventions")
}
tasks.register<Copy>("copyJar")
// 复制jar依赖包
tasks.named<Copy>("copyJar") {
delete("$buildDir/libs/lib")
from(configurations.runtimeClasspath).into("$buildDir/libs/lib")
}
// 打包时排除其他依赖jar
tasks.named<org.springframework.boot.gradle.tasks.bundling.BootJar>("bootJar") {
setExcludes(listOf("*.jar"))
dependsOn("copyJar")
manifest {
// 指定Class-Path,运行时不用在命令行指定loader.path
attributes(
"Class-Path" to configurations.runtimeClasspath.get().files.map { "lib/${it.name}" }.joinToString(" ")
)
}
}
dependencies {
implementation(project(":quartz"))
implementation(project(":generator"))
implementation(project(":workflow"))
implementation(project(":system"))
implementation(project(":archives"))
implementation(project(":tools"))
}
description = "entrance-web"
四、build
使用bootJar打包,将会在build/lib下存放外部依赖包,
五、存在问题
使用这种方式打包后启动Jar包里依赖的其他模块的依赖jar包是*-plain.jar,并不包含该模块自己的依赖类,部署的时候如果只是更改了模块代码,直接替换module-plain.jar即可,如果添加或删除了外部依赖,则需要将外部依赖的jar手动复制。
标签:src,拆分,jar,kts,boogle,build,模块,gradle 来源: https://www.cnblogs.com/yourblog/p/16641093.html