-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
166 lines (131 loc) · 4.03 KB
/
build.gradle
File metadata and controls
166 lines (131 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
plugins {
id 'java-library'
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'application'
}
group = 'cxy.fun'
version = '1.4-build.3'
apply from: 'export-deps.gradle'
repositories {
mavenCentral()
}
configurations {
pack{
extendsFrom implementation // 继承implementation的所有特性
canBeConsumed = false // 避免被其他项目依赖
canBeResolved = true // 允许解析依赖
}
}
jar {
from {
// 只包含自定义配置中的依赖
configurations.pack.collect { it.isDirectory() ? it : zipTree(it) }
}
// 包含你自己的编译输出
from sourceSets.main.output
exclude('LICENSE.txt', 'NOTICE.txt', 'rootdoc.txt')
exclude 'META-INF/*.RSA', 'META-INF/*.SF', 'META-INF/*.DSA'
exclude 'META-INF/NOTICE', 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE', 'META-INF/LICENSE.txt'
exclude 'META-INF/DEPENDENCIES'
manifest {
attributes(
'Main-Class': 'com.fun.inject.Main', // 指定主类
'Implementation-Title': project.name,
'Implementation-Version': project.version
)
}
}
build{
shadowJar
}
dependencies {
// ASM 核心库
implementation 'org.ow2.asm:asm:9.6' // 截至2024年5月最新版本
// ASM 树API(可选)
implementation 'org.ow2.asm:asm-tree:9.6'
// ASM Commons 工具(可选)
implementation 'org.ow2.asm:asm-commons:9.6'
// ASM Util 工具(可选)
implementation 'org.ow2.asm:asm-util:9.6'
implementation 'commons-io:commons-io:2.16.1'
implementation 'net.java.dev.jna:jna:+' // 核心JNA库
implementation 'net.java.dev.jna:jna-platform:+' // 平台特定的功能
implementation 'org.apache.commons:commons-compress:1.26.0'
implementation 'org.jetbrains:annotations:24.1.0'
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
implementation 'io.netty:netty-all:4.1.109.Final'
implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
implementation 'org.apache.logging.log4j:log4j-api:2.23.1'
}
ext {
cmakeBuildDir = file("$rootDir/cmake-build-debug")
nativeLibsDir = file("build/natives")
cmakeBuildType = project.hasProperty('debug') ? 'Debug' : 'Release'
}
tasks.register('createBuildDirs') {
doLast {
cmakeBuildDir.mkdirs()
nativeLibsDir.mkdirs()
}
}
tasks.register('cmakeConfigure', Exec) {
dependsOn 'createBuildDirs'
// 允许命令执行失败(手动检查退出码)
ignoreExitValue = true
commandLine 'cmake',
"-B${cmakeBuildDir}",
"-DCMAKE_INSTALL_PREFIX=${nativeLibsDir}",
"-DCMAKE_BUILD_TYPE=${cmakeBuildType}",
"-S${projectDir}"
// 正确的退出码检查方式
doLast {
}
}
tasks.register('cmakeBuild', Exec) {
//dependsOn 'cmakeConfigure'
// 允许命令执行失败(手动检查退出码)
//ignoreExitValue = true
if (org.gradle.internal.os.OperatingSystem.current().windows) {
commandLine 'cmake',
'--build', cmakeBuildDir,
'--config', cmakeBuildType,
'--target', 'all'
} else {
commandLine 'cmake',
'--build', cmakeBuildDir,
'--parallel', Runtime.runtime.availableProcessors().toString(),
'--target', 'install'
}
// 正确的退出码检查方式
doLast {
}
}
tasks.register('cmakeClean', Delete) {
delete cmakeBuildDir
delete nativeLibsDir
}
compileJava {
dependsOn 'cmakeBuild'
}
application {
mainClass = 'com.fun.inject.Main'
}
processResources {
from(nativeLibsDir) {
into 'natives'
include '**/*.dll', '**/*.so', '**/*.dylib'
}
}
clean {
dependsOn 'cmakeClean'
}
// 禁用默认的 jar 任务
jar.enabled = false
// 确保 build 任务依赖 shadowJar
build.dependsOn shadowJar
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}