build(gradle): 优化项目构建并添加 ProGuard 混淆
- 移除了不必要的依赖项和构建配置 - 添加了 ProGuard 混淆任务 - 优化了 CEF 设置,提高了性能和减少了日志输出 - 调整了项目结构,使构建过程更加清晰和高效
This commit is contained in:
230
build.gradle
230
build.gradle
@@ -5,10 +5,12 @@ plugins {
|
||||
id 'org.openjfx.javafxplugin' version '0.1.0'
|
||||
id 'org.springframework.boot' version '3.2.0'
|
||||
id 'io.spring.dependency-management' version '1.1.4'
|
||||
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false // 关闭 shadow
|
||||
}
|
||||
|
||||
configurations {
|
||||
all*.exclude group: 'org.openjfx', module: 'javafx'
|
||||
proguardLib
|
||||
}
|
||||
|
||||
// JDK 版本检查
|
||||
@@ -22,262 +24,152 @@ group = 'com.axis.innovators.box'
|
||||
version = '0.0.1'
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url 'https://maven.aliyun.com/repository/public'
|
||||
metadataSources {
|
||||
mavenPom()
|
||||
artifact()
|
||||
ignoreGradleMetadataRedirection()
|
||||
}
|
||||
}
|
||||
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
|
||||
maven { url 'https://maven.aliyun.com/repository/public' }
|
||||
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
|
||||
maven { url 'https://jitpack.io' }
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
|
||||
}
|
||||
//tasks.named("bootJar") {
|
||||
// enabled = false
|
||||
//}
|
||||
|
||||
dependencies {
|
||||
proguardLib files('libs/proguard.jar')
|
||||
|
||||
testImplementation platform('org.junit:junit-bom:5.10.0')
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter'
|
||||
implementation 'org.commonmark:commonmark:0.24.0'
|
||||
implementation 'org.commonjava.googlecode.markdown4j:markdown4j:2.2-cj-1.1'
|
||||
implementation 'com.google.code.gson:gson:2.8.9'
|
||||
|
||||
implementation 'org.apache.logging.log4j:log4j-api:2.20.0'
|
||||
implementation 'org.apache.logging.log4j:log4j-core:2.20.0'
|
||||
implementation 'org.apache.logging.log4j:log4j-slf4j-impl:2.20.0'
|
||||
|
||||
implementation 'org.ow2.asm:asm:9.7.1'
|
||||
implementation 'org.ow2.asm:asm-commons:9.7.1'
|
||||
implementation 'org.ow2.asm:asm-analysis:9.7.1'
|
||||
implementation 'org.ow2.asm:asm-util:9.7.1'
|
||||
implementation 'org.ow2.asm:asm-tree:9.7.1'
|
||||
implementation 'net.bytebuddy:byte-buddy:1.17.6'
|
||||
|
||||
implementation 'org.jsoup:jsoup:1.17.2'
|
||||
|
||||
implementation 'com.google.code.gson:gson:2.8.9'
|
||||
|
||||
//implementation 'com.formdev:flatlaf:0.26'
|
||||
implementation 'commons-io:commons-io:2.14.0'
|
||||
|
||||
|
||||
|
||||
implementation 'com.formdev:flatlaf:3.2.1' // FlatLaf核心
|
||||
implementation 'com.formdev:flatlaf-extras:3.2.1' // 扩展组件
|
||||
implementation 'com.formdev:flatlaf-intellij-themes:3.2.1' // 官方主题包
|
||||
|
||||
implementation 'com.formdev:flatlaf:3.2.1'
|
||||
implementation 'com.formdev:flatlaf-extras:3.2.1'
|
||||
implementation 'com.formdev:flatlaf-intellij-themes:3.2.1'
|
||||
implementation 'org.python:jython-standalone:2.7.3'
|
||||
implementation 'org.graalvm.python:python-embedding:24.2.1'
|
||||
|
||||
implementation files('libs/JNC-1.0-jnc.jar')
|
||||
implementation files('libs/dog api 1.3.jar')
|
||||
implementation files('libs/DesktopWallpaperSdk-1.0-SNAPSHOT.jar')
|
||||
|
||||
implementation 'org.fxmisc.richtext:richtextfx:0.11.0' // 更新后的richtextfx
|
||||
implementation 'org.bitbucket.mstrobel:procyon-core:0.5.36' // 使用JitPack版本
|
||||
implementation 'org.fxmisc.richtext:richtextfx:0.11.0'
|
||||
implementation 'org.bitbucket.mstrobel:procyon-core:0.5.36'
|
||||
implementation 'org.bitbucket.mstrobel:procyon-compilertools:0.5.36'
|
||||
|
||||
// 必须的核心依赖
|
||||
implementation 'com.fifesoft:rsyntaxtextarea:3.5.4'
|
||||
|
||||
// 可选UI增强
|
||||
implementation 'com.fifesoft:rstaui:3.3.1'
|
||||
implementation 'com.fifesoft:languagesupport:3.3.0'
|
||||
implementation 'com.fifesoft:autocomplete:3.3.2'
|
||||
|
||||
implementation 'org.apache.commons:commons-compress:1.23.0'
|
||||
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.2'
|
||||
implementation 'org.controlsfx:controlsfx:11.1.2' // 现代化UI组件
|
||||
implementation 'com.dlsc.formsfx:formsfx-core:11.6.0' // 表单组件
|
||||
implementation 'net.sourceforge.plantuml:plantuml:8059' // UML支持(可选)
|
||||
|
||||
implementation 'org.controlsfx:controlsfx:11.1.2'
|
||||
implementation 'com.dlsc.formsfx:formsfx-core:11.6.0'
|
||||
implementation 'net.sourceforge.plantuml:plantuml:8059'
|
||||
implementation 'com.google.code.gson:gson:2.10.1'
|
||||
|
||||
implementation 'org.openjfx:javafx-controls:21'
|
||||
implementation 'org.benf:cfr:0.152'
|
||||
|
||||
implementation 'com.github.javaparser:javaparser-core:3.25.1'
|
||||
|
||||
implementation 'com.1stleg:jnativehook:2.1.0'
|
||||
|
||||
//implementation 'org.springframework.boot:spring-boot-starter-web' // Web支持
|
||||
//implementation 'org.springframework.boot:spring-boot-starter-data-jpa' // JPA数据库支持
|
||||
//implementation 'org.springframework.boot:spring-boot-starter-validation' // 参数校验
|
||||
|
||||
// 安全相关依赖
|
||||
//implementation 'org.springframework.boot:spring-boot-starter-security' // Spring Security
|
||||
//implementation 'io.jsonwebtoken:jjwt-api:0.12.3' // JWT API
|
||||
//runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.3', // JWT实现
|
||||
// 'io.jsonwebtoken:jjwt-jackson:0.12.3' // JWT序列化
|
||||
|
||||
implementation 'org.json:json:20230618'
|
||||
|
||||
implementation 'org.lwjgl:lwjgl:3.3.1'
|
||||
implementation 'org.lwjgl:lwjgl-glfw:3.3.1'
|
||||
implementation 'org.lwjgl:lwjgl-opengl:3.3.1'
|
||||
implementation 'org.lwjgl:lwjgl:3.3.1:natives-windows' // Windows natives
|
||||
implementation 'org.lwjgl:lwjgl:3.3.1:natives-windows'
|
||||
implementation 'org.lwjgl:lwjgl-glfw:3.3.1:natives-windows'
|
||||
implementation 'org.lwjgl:lwjgl-opengl:3.3.1:natives-windows'
|
||||
|
||||
implementation 'org.bytedeco:javacv-platform:1.5.7' // JavaCV
|
||||
implementation 'org.bytedeco:javacpp-platform:1.5.7' // JavaCPP
|
||||
|
||||
implementation 'org.bytedeco:javacv-platform:1.5.7'
|
||||
implementation 'org.bytedeco:javacpp-platform:1.5.7'
|
||||
implementation 'com.madgag:animated-gif-lib:1.4'
|
||||
implementation 'org.openjfx:javafx-web:17'
|
||||
|
||||
|
||||
runtimeOnly 'com.mysql:mysql-connector-j'
|
||||
|
||||
// 开发工具
|
||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||
|
||||
// 测试依赖
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
testImplementation 'org.springframework.security:spring-security-test'
|
||||
|
||||
implementation 'com.kitfox.svg:svg-salamander:1.0'
|
||||
|
||||
implementation 'com.vladsch.flexmark:flexmark:0.64.8'
|
||||
|
||||
// SystemTray4J 核心库
|
||||
implementation 'com.github.kwhat:jnativehook:2.2.2'
|
||||
implementation 'com.dustinredmond.fxtrayicon:FXTrayIcon:4.0.1' // 增强版
|
||||
|
||||
// JavaFX 模块
|
||||
implementation 'com.dustinredmond.fxtrayicon:FXTrayIcon:4.0.1'
|
||||
implementation 'org.openjfx:javafx-graphics:21'
|
||||
|
||||
implementation 'me.friwi:jcefmaven:122.1.10'
|
||||
|
||||
implementation 'com.alphacephei:vosk:0.3.45' // Java API
|
||||
implementation 'com.alphacephei:vosk:0.3.45'
|
||||
implementation 'net.java.dev.jna:jna:5.13.0'
|
||||
implementation 'net.java.dev.jna:jna-platform:5.13.0'
|
||||
|
||||
// 高性能音频处理
|
||||
implementation 'org.apache.commons:commons-math3:3.6.1'
|
||||
implementation 'com.google.guava:guava:31.1-jre'
|
||||
|
||||
implementation 'com.github.javaparser:javaparser-symbol-solver-core:3.25.9'
|
||||
|
||||
implementation 'org.bitbucket.mstrobel:procyon-core:0.6.0'
|
||||
implementation 'org.bitbucket.mstrobel:procyon-compilertools:0.6.0'
|
||||
//implementation 'org.jetbrains.java.decompiler:fernflower:1.9.0'
|
||||
|
||||
// 中文拼音处理
|
||||
implementation 'com.belerweb:pinyin4j:2.5.1'
|
||||
|
||||
// 音频I/O
|
||||
implementation 'commons-io:commons-io:2.18.0'
|
||||
implementation 'jflac:jflac:1.3' // FLAC支持
|
||||
|
||||
implementation 'jflac:jflac:1.3'
|
||||
implementation 'com.github.axet:TarsosDSP:2.4'
|
||||
|
||||
implementation 'org.json:json:20231013'
|
||||
|
||||
// Eclipse 组件
|
||||
// https://mvnrepository.com/artifact/org.eclipse.swt/org.eclipse.swt.win32.win32.x86_64
|
||||
//implementation 'org.eclipse.swt:org.eclipse.swt.win32.win32.x86_64:4.3'
|
||||
//
|
||||
//// 基础 Eclipse 组件
|
||||
//implementation 'org.eclipse.platform:org.eclipse.jface:3.36.0'
|
||||
//implementation 'org.eclipse.platform:org.eclipse.jface.text:3.27.0' // 使用兼容版本
|
||||
//implementation 'org.eclipse.platform:org.eclipse.core.runtime:3.33.0'
|
||||
//implementation 'org.eclipse.platform:org.eclipse.equinox.common:3.20.0'
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 分离依赖项到 libs 目录
|
||||
configurations.all {
|
||||
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
|
||||
}
|
||||
|
||||
// 复制依赖到 libs 目录
|
||||
task copyDependencies(type: Copy) {
|
||||
from configurations.runtimeClasspath
|
||||
into "$buildDir/libs/libs"
|
||||
}
|
||||
|
||||
// 执行我生成jar
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Main-Class': 'com.axis.innovators.box.Main',
|
||||
'Class-Path': configurations.runtimeClasspath.files.collect { "libs/$it.name" }.join(' ')
|
||||
}
|
||||
// 原始 jar 打包(不含依赖)
|
||||
tasks.jar {
|
||||
dependsOn copyDependencies
|
||||
archiveBaseName.set("${rootProject.name}")
|
||||
archiveVersion.set("${version}")
|
||||
}
|
||||
|
||||
// 测试配置
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
systemProperty "java.system.class.loader", "com.axis.innovators.box.plugins.BoxClassLoader"
|
||||
// ProGuard 混淆任务
|
||||
task obfuscateJar(type: JavaExec) {
|
||||
dependsOn jar
|
||||
group = "build"
|
||||
description = "使用 ProGuard 混淆并生成映射表"
|
||||
|
||||
// 确保测试能看到依赖
|
||||
classpath = files(sourceSets.test.output) +
|
||||
files("$buildDir/libs/libs") +
|
||||
configurations.testRuntimeClasspath
|
||||
}
|
||||
mainClass = 'proguard.ProGuard'
|
||||
classpath = configurations.proguardLib
|
||||
|
||||
// 处理开源文档文件
|
||||
sourceSets {
|
||||
main {
|
||||
resources {
|
||||
exclude '**/*.md'
|
||||
}
|
||||
}
|
||||
openSourceDocs {
|
||||
resources {
|
||||
srcDir 'src/main/resources'
|
||||
include '**/*.md'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(JavaExec).configureEach {
|
||||
jvmArgs = [
|
||||
'-Djava.system.class.loader=com.axis.innovators.box.plugins.BoxClassLoader'
|
||||
args = [
|
||||
'-injars', "$buildDir/libs/${rootProject.name}-${version}.jar",
|
||||
'-outjars', "$buildDir/libs/${rootProject.name}-${version}-obf.jar",
|
||||
'-libraryjars', "${System.getProperty('java.home')}/jmods/java.base.jmod",
|
||||
'-printmapping', "$buildDir/libs/output.srg",
|
||||
'-keep class com.axis.innovators.box.plugins.**',
|
||||
'-keep class com.axis.innovators.box.plugins.BoxClassLoader{*;}',
|
||||
'-keeppackagenames', 'com.axis.innovators.box',
|
||||
'-keeppackagenames', 'com.axis.innovators.box.plugins',
|
||||
'-keepnames', 'class com.axis.innovators.box.**',
|
||||
'-keepnames', 'class com.axis.innovators.box.plugins.**',
|
||||
'-dontwarn',
|
||||
'-dontoptimize',
|
||||
'-dontshrink',
|
||||
'-keepattributes', 'Signature,InnerClasses,EnclosingMethod,RuntimeVisibleAnnotations,RuntimeInvisibleAnnotations,RuntimeVisibleParameterAnnotations,RuntimeInvisibleParameterAnnotations,Deprecated,SourceFile,LineNumberTable,LocalVariableTable,LocalVariableTypeTable'
|
||||
]
|
||||
}
|
||||
|
||||
javafx {
|
||||
version = "21"
|
||||
modules = [ 'javafx.controls', 'javafx.fxml' ]
|
||||
build {
|
||||
dependsOn obfuscateJar
|
||||
}
|
||||
|
||||
// 单独打包文档
|
||||
task packageOpenSourceDocs(type: Jar) {
|
||||
archiveClassifier = 'docs'
|
||||
from sourceSets.openSourceDocs.resources
|
||||
destinationDirectory = file("$buildDir/libs/docs")
|
||||
}
|
||||
|
||||
// 完整的 application 配置
|
||||
application {
|
||||
mainClass = 'com.axis.innovators.box.Main'
|
||||
|
||||
// 确保运行时参数生效
|
||||
applicationDefaultJvmArgs = [
|
||||
"-Djava.system.class.loader=com.axis.innovators.box.plugins.BoxClassLoader",
|
||||
"-Dloader.library.path=$buildDir/libs/libs",
|
||||
'-Dfile.encoding=UTF-8'
|
||||
]
|
||||
}
|
||||
|
||||
// 创建可运行分发
|
||||
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"
|
||||
}
|
||||
task runClient(type: JavaExec) {
|
||||
group = "application"
|
||||
description = "运行 com.axis.innovators.box.Main"
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
mainClass = "com.axis.innovators.box.Main"
|
||||
jvmArgs = ["-Dfile.encoding=UTF-8"]
|
||||
}
|
||||
|
||||
// 默认构建任务
|
||||
build.dependsOn release
|
||||
BIN
libs/proguard.jar
Normal file
BIN
libs/proguard.jar
Normal file
Binary file not shown.
@@ -55,18 +55,21 @@ public class CefAppManager {
|
||||
private static void initializeDefaultSettings() {
|
||||
initLock.lock();
|
||||
try {
|
||||
settings.windowless_rendering_enabled = true;
|
||||
settings.javascript_flags = "--expose-gc";
|
||||
settings.windowless_rendering_enabled = false;
|
||||
settings.javascript_flags = "";
|
||||
settings.cache_path = FolderCreator.getLibraryFolder() + "/jcef/cache";
|
||||
settings.root_cache_path = FolderCreator.getLibraryFolder() + "/jcef/cache";
|
||||
settings.persist_session_cookies = true;
|
||||
settings.log_severity = CefSettings.LogSeverity.LOGSEVERITY_VERBOSE;
|
||||
settings.persist_session_cookies = false;
|
||||
settings.log_severity = CefSettings.LogSeverity.LOGSEVERITY_WARNING;
|
||||
|
||||
String subprocessPath = FolderCreator.getLibraryFolder() + "/jcef/lib/win64/jcef_helper.exe";
|
||||
validateSubprocessPath(subprocessPath);
|
||||
settings.browser_subprocess_path = subprocessPath;
|
||||
|
||||
logger.info("Default CEF settings initialized");
|
||||
//settings.background_color = new Color(255, 255, 255, 0);
|
||||
settings.command_line_args_disabled = false;
|
||||
|
||||
logger.info("Optimized CEF settings initialized");
|
||||
} finally {
|
||||
initLock.unlock();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user