181 lines
5.0 KiB
Groovy
181 lines
5.0 KiB
Groovy
import org.panteleyev.jpackage.ImageType
|
||
|
||
buildscript {
|
||
repositories {
|
||
google()
|
||
mavenCentral()
|
||
}
|
||
}
|
||
|
||
plugins {
|
||
id 'java'
|
||
id 'io.franzbecker.gradle-lombok' version '3.0.0'
|
||
id 'application'
|
||
id 'org.openjfx.javafxplugin' version '0.1.0'
|
||
// 不再使用模块插件,移除 org.javamodularity.moduleplugin
|
||
// id 'org.javamodularity.moduleplugin' version '1.8.12'
|
||
id("org.panteleyev.jpackageplugin") version "1.6.1"
|
||
}
|
||
|
||
group = project_group
|
||
version = project_version
|
||
|
||
repositories {
|
||
mavenCentral()
|
||
}
|
||
|
||
ext {
|
||
junitVersion = '5.10.0'
|
||
}
|
||
|
||
// 指定 JDK 版本
|
||
java {
|
||
toolchain {
|
||
languageVersion = JavaLanguageVersion.of(17)
|
||
}
|
||
}
|
||
|
||
sourceCompatibility = '17'
|
||
targetCompatibility = '17'
|
||
|
||
tasks.withType(JavaCompile).configureEach {
|
||
options.release = 17
|
||
options.encoding = 'UTF-8'
|
||
}
|
||
|
||
// 平台判定,自动添加 JavaFX 依赖的 classifier
|
||
def osName = org.gradle.internal.os.OperatingSystem.current()
|
||
def javafxPlatform
|
||
if (osName.isWindows()) {
|
||
javafxPlatform = 'win'
|
||
} else if (osName.isMacOsX()) {
|
||
javafxPlatform = 'mac'
|
||
} else if (osName.isLinux()) {
|
||
javafxPlatform = 'linux'
|
||
} else {
|
||
throw new GradleException("Unsupported OS for JavaFX: $osName")
|
||
}
|
||
|
||
def javafxVersion = '17.0.6'
|
||
|
||
dependencies {
|
||
// JavaFX 必须带平台后缀,classpath 模式必须
|
||
implementation "org.openjfx:javafx-controls:$javafxVersion:$javafxPlatform"
|
||
implementation "org.openjfx:javafx-fxml:$javafxVersion:$javafxPlatform"
|
||
|
||
implementation 'ch.qos.logback:logback-classic:1.5.18'
|
||
implementation 'ch.qos.logback:logback-core:1.5.18'
|
||
implementation 'ch.qos.logback:logback-classic:1.5.6'
|
||
implementation 'commons-cli:commons-cli:1.9.0'
|
||
implementation 'com.alibaba:easyexcel:4.0.3'
|
||
implementation 'org.apache.pdfbox:pdfbox:3.0.5'
|
||
implementation 'com.github.albfernandez:javadbf:1.14.1'
|
||
implementation 'org.apache.poi:poi-ooxml:5.4.1'
|
||
implementation 'com.intellij:annotations:12.0'
|
||
|
||
compileOnly 'org.projectlombok:lombok:1.18.38'
|
||
annotationProcessor 'org.projectlombok:lombok:1.18.38'
|
||
|
||
testCompileOnly 'org.projectlombok:lombok:1.18.38'
|
||
testAnnotationProcessor 'org.projectlombok:lombok:1.18.38'
|
||
|
||
testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion"
|
||
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion"
|
||
}
|
||
|
||
application {
|
||
// 取消模块化,去掉 mainModule
|
||
mainClass = 'top.r3944realms.docchecktoolrefactored.Main'
|
||
}
|
||
|
||
javafx {
|
||
version = javafxVersion
|
||
// 这里的 modules 只为插件识别,实际classpath方式运行时不起作用
|
||
modules = ['javafx.controls', 'javafx.fxml']
|
||
}
|
||
|
||
processResources {
|
||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||
}
|
||
|
||
test {
|
||
useJUnitPlatform()
|
||
configurations.configureEach {
|
||
exclude group: 'org.apache.logging.log4j', module: 'log4j-slf4j-impl'
|
||
}
|
||
}
|
||
|
||
// 创建日志目录任务
|
||
tasks.register('createLogDir') {
|
||
doLast {
|
||
mkdir "${projectDir}/logs"
|
||
}
|
||
}
|
||
|
||
processResources.dependsOn createLogDir
|
||
|
||
// 其他自定义任务按需保留或调整
|
||
tasks.register('runCli', JavaExec) {
|
||
group = 'application'
|
||
description = 'Run the application in CLI mode'
|
||
|
||
classpath = sourceSets.main.runtimeClasspath
|
||
mainClass = 'top.r3944realms.docchecktoolrefactored.Main'
|
||
|
||
// 默认参数,可以覆盖
|
||
args '--cli', '-v'
|
||
|
||
// 可以添加更多默认参数
|
||
if (project.hasProperty('cliArgs')) {
|
||
args project.property('cliArgs').split()
|
||
}
|
||
}
|
||
|
||
// 可选:创建生成可执行JAR的任务
|
||
tasks.register('buildFatJar', Jar) {
|
||
group = 'build'
|
||
description = 'Builds a standalone JAR with all dependencies'
|
||
|
||
manifest {
|
||
attributes(
|
||
'Main-Class': 'top.r3944realms.docchecktoolrefactored.Main'
|
||
)
|
||
}
|
||
|
||
from {
|
||
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
|
||
}
|
||
with jar // 继承主 jar 的内容
|
||
|
||
archiveBaseName.set(project_name)
|
||
archiveVersion.set(project_version)
|
||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||
}
|
||
|
||
// =================== 轻便版打包 ===================
|
||
|
||
tasks.register('buildPortable', Exec) {
|
||
group = 'distribution'
|
||
description = 'Build portable EXE (no installer)'
|
||
|
||
dependsOn buildFatJar
|
||
|
||
commandLine 'jpackage',
|
||
'--name', 'DocCheckTool',
|
||
'--input', "$buildDir/libs",
|
||
'--main-jar', "${project_name}-${project_version}.jar",
|
||
'--main-class', application.mainClass.get(),
|
||
'--type', 'app-image', // ⚠️ 轻便版不生成安装器
|
||
'--app-version', project_version,
|
||
'--vendor', 'r3944realms',
|
||
'--dest', "$buildDir/distributions",
|
||
'--java-options', '-Dfile.encoding=UTF-8',
|
||
'--java-options', '-Xmx4G',
|
||
'--java-options', '-Xms256m',
|
||
'--verbose',
|
||
'--icon', file('src/main/resources/img/logo256x.ico').absolutePath
|
||
|
||
doFirst {
|
||
mkdir "$buildDir/distributions"
|
||
}
|
||
} |