-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild.gradle
More file actions
166 lines (138 loc) · 5.06 KB
/
build.gradle
File metadata and controls
166 lines (138 loc) · 5.06 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
/*
* This file is part of VelocityTitle(https://github.com/RedStarMC/VelocityTitle).
*
* Copyright (C) RedStarMC and contributors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
******************************************************************************/
import org.apache.tools.ant.filters.ReplaceTokens
plugins{
id 'java-library'
}
def now_version = "0.2.0"
allprojects {
apply {
plugin 'java-library'
}
group = 'top.redstarmc.plugin.velocitytitle'
version = now_version
repositories {
mavenCentral() //Maven 存储库
maven { url 'https://repo.codemc.io/repository/maven-releases/' }
}
dependencies {
compileOnly 'org.jetbrains:annotations:23.0.0'
implementation 'com.moandjiezana.toml:toml4j:0.7.2'
implementation "net.kyori:adventure-api:4.25.0"
}
// 编译 固定 UTF-8 编码
tasks.withType(JavaCompile).configureEach {
options.encoding = "UTF-8"
}
// Javadoc 固定 UTF-8 编码
tasks.withType(Javadoc).tap {
configureEach {
options.encoding = "UTF-8"
}
}
// 固定使用 Java21
java {
toolchain.languageVersion.set(JavaLanguageVersion.of(21))
}
processResources {
// 匹配所有资源文件
filesMatching('**/*') {
filter(ReplaceTokens, tokens: [encoding: 'UTF-8'])
filter { Object line ->
line.toString().replace('@VERSION@', project.version)
}
}
filteringCharset = 'UTF-8'
}
}
subprojects {
// 1. 配置原始 Jar 任务(包含自身代码和core模块代码)
tasks.withType(Jar).tap {
configureEach {
group = 'build'
destinationDirectory.set(rootProject.file("${rootProject.rootDir}/build/jars"))
archiveClassifier.set('original') // 明确标记为原始 JAR
// 包含自身代码、资源和core模块代码
from sourceSets.main.output
// 仅对velocity和spigot模块添加core代码
if (project.name in ['velocity', 'spigot']) {
from project(':core').sourceSets.main.output
}
}
}
// 2. 配置包含依赖的 JAR 任务(xxx.jar)
tasks.register('jarWithDependencies', Jar) {
group = 'build'
destinationDirectory.set(rootProject.file("${rootProject.rootDir}/build/jars"))
archiveBaseName.set(jar.archiveBaseName)
archiveClassifier.set('')
from {
sourceSets.main.output // 包含当前模块的代码和资源
// 仅对velocity和spigot模块添加core代码
if (project.name in ['velocity', 'spigot']) {
project(':core').sourceSets.main.output
}
}
// 收集外部依赖(排除项目内的 original.jar)
from {
configurations.runtimeClasspath.collect { file ->
// 排除项目内生成的 original.jar(避免重复打包)
if (file.name.endsWith("-original.jar")) {
null // 跳过 original.jar
} else {
file.isDirectory() ? file : zipTree(file)
}
}.findAll { it != null } // 过滤掉 null 值
}
exclude 'META-INF/*', '*.MF'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
// 3. 确保 build 任务同时执行两个 JAR 任务
tasks.named('build') {
dependsOn(tasks.named('jar'), tasks.named('jarWithDependencies'))
}
}
tasks.register('createAllJar', Jar) {
group = 'build'
archiveBaseName.set('VelocityTitle')
archiveVersion.set(now_version)
// 收集所有子模块的类文件和资源文件
from {
subprojects.collect { subproject ->
[subproject.file("build/classes/java/main"),
subproject.file("build/resources/main")].findAll { it != null && it.exists() }
}
}
// 收集所有子模块的依赖
from {
subprojects.collectMany { subproject ->
subproject.configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
exclude 'META-INF/*', '*.MF'
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
destinationDirectory.set(rootProject.file("${rootProject.rootDir}/build/jars"))
// 添加对子模块构建任务的依赖
subprojects.each { project ->
dependsOn project.tasks.named('build')
}
}
tasks.named('build') {
finalizedBy('createAllJar')
}