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' // 你可以根据需要保留 jlink 插件,但推荐取消模块化后暂时不用它 id 'org.beryx.jlink' version '2.26.0' apply false } 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" // 你项目的其他依赖(老库走classpath) implementation 'ch.qos.logback:logback-classic:1.5.6' implementation 'org.apache.logging.log4j:log4j-slf4j2-impl:2.20.0' 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('buildCliJar', Jar) { group = 'build' description = 'Builds a standalone JAR for CLI mode' manifest { attributes 'Main-Class': 'top.r3944realms.docchecktoolrefactored.Main' } from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } with jar archiveBaseName = 'doc-check-tool-cli' duplicatesStrategy = DuplicatesStrategy.EXCLUDE }