build(gradle): 重构构建配置并添加新功能
- 更新 Shadow 插件版本 - 添加 JDK 版本检查 - 分离依赖项到 libs 目录- 修改 jar 任务以包含 Class-Path 属性 - 更新测试配置 - 添加开源文档处理和打包功能 - 创建可运行分发包 - 设置默认构建任务
This commit is contained in:
73
build.gradle
73
build.gradle
@@ -1,10 +1,10 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'application'
|
id 'application'
|
||||||
id 'com.github.johnrengelman.shadow' version '7.1.2'
|
|
||||||
id 'edu.sc.seis.launch4j' version '2.5.4'
|
id 'edu.sc.seis.launch4j' version '2.5.4'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// JDK 版本检查
|
||||||
def requiredJavaVersion = 20
|
def requiredJavaVersion = 20
|
||||||
def currentJavaVersion = JavaVersion.current().majorVersion.toInteger()
|
def currentJavaVersion = JavaVersion.current().majorVersion.toInteger()
|
||||||
if (currentJavaVersion != requiredJavaVersion) {
|
if (currentJavaVersion != requiredJavaVersion) {
|
||||||
@@ -39,19 +39,80 @@ dependencies {
|
|||||||
implementation 'org.ow2.asm:asm-tree:7.1'
|
implementation 'org.ow2.asm:asm-tree:7.1'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 分离依赖项到 libs 目录
|
||||||
|
task copyDependencies(type: Copy) {
|
||||||
|
from configurations.runtimeClasspath
|
||||||
|
into "$buildDir/libs/libs"
|
||||||
|
}
|
||||||
|
|
||||||
|
// 执行我生成jar
|
||||||
jar {
|
jar {
|
||||||
manifest {
|
manifest {
|
||||||
attributes 'Main-Class': 'com.axis.innovators.box.Main'
|
attributes 'Main-Class': 'com.axis.innovators.box.Main',
|
||||||
|
'Class-Path': configurations.runtimeClasspath.files.collect { "libs/$it.name" }.join(' ')
|
||||||
|
}
|
||||||
|
dependsOn copyDependencies
|
||||||
|
}
|
||||||
|
|
||||||
|
// 测试配置
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
systemProperty "java.system.class.loader", "com.axis.innovators.box.plugins.BoxClassLoader"
|
||||||
|
|
||||||
|
// 确保测试能看到依赖
|
||||||
|
classpath = files(sourceSets.test.output) +
|
||||||
|
files("$buildDir/libs/libs") +
|
||||||
|
configurations.testRuntimeClasspath
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理开源文档文件
|
||||||
|
sourceSets {
|
||||||
|
main {
|
||||||
|
resources {
|
||||||
|
exclude '**/*.md'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
openSourceDocs {
|
||||||
|
resources {
|
||||||
|
srcDir 'src/main/resources'
|
||||||
|
include '**/*.md'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 单独打包文档
|
||||||
|
task packageOpenSourceDocs(type: Jar) {
|
||||||
|
archiveClassifier = 'docs'
|
||||||
|
from sourceSets.openSourceDocs.resources
|
||||||
|
destinationDirectory = file("$buildDir/libs/docs")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 完整的 application 配置
|
||||||
application {
|
application {
|
||||||
mainClass = 'com.axis.innovators.box.Main'
|
mainClass = 'com.axis.innovators.box.Main'
|
||||||
|
|
||||||
|
// 确保运行时参数生效
|
||||||
applicationDefaultJvmArgs = [
|
applicationDefaultJvmArgs = [
|
||||||
"-Djava.system.class.loader=com.axis.innovators.box.plugins.BoxClassLoader"
|
"-Djava.system.class.loader=com.axis.innovators.box.plugins.BoxClassLoader",
|
||||||
|
"-Dloader.library.path=$buildDir/libs/libs"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
test {
|
// 创建可运行分发
|
||||||
useJUnitPlatform()
|
tasks.register('release') {
|
||||||
}
|
dependsOn build, packageOpenSourceDocs
|
||||||
|
|
||||||
|
doLast {
|
||||||
|
copy {
|
||||||
|
from "$buildDir/libs"
|
||||||
|
into "$buildDir/dist"
|
||||||
|
include '*.jar'
|
||||||
|
include 'docs/**'
|
||||||
|
include 'libs/**'
|
||||||
|
}
|
||||||
|
println "Release package ready at: $buildDir/dist"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 默认构建任务
|
||||||
|
build.dependsOn release
|
||||||
Reference in New Issue
Block a user