-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
296 lines (255 loc) · 8.32 KB
/
build.gradle
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import io.franzbecker.gradle.lombok.task.DelombokTask
import groovy.json.*
import java.util.regex.*
buildscript {
repositories {
mavenCentral()
jcenter()
maven {
name = "forge"
url = "http://files.minecraftforge.net/maven"
}
}
dependencies {
classpath 'net.minecraftforge.gradle:ForgeGradle:2.3-SNAPSHOT'
}
}
plugins {
id "com.matthewprenger.cursegradle" version "1.0.9"
id "io.franzbecker.gradle-lombok" version "1.8"
id "com.github.ben-manes.versions" version "0.15.0"
}
apply plugin: "net.minecraftforge.gradle.forge"
apply plugin: "maven"
apply plugin: "maven-publish"
def getChangelog() {
Pattern pattern = Pattern.compile("^.+?\n-+\n\n((?:\\* .+?\n)+)");
Matcher match = pattern.matcher(file("CHANGELOG.md").text.replaceAll("\r", ""));
if (match.find()) {
String res = match.group(1);
return res.substring(0, res.length() - 1);
} else {
return "";
}
}
def getVersionType() {
def lower_version = version.toLowerCase();
if (lower_version.contains("beta") || lower_version.contains("rc"))
return "beta";
else if (lower_version.contains("alpha"))
return "alpha";
else
return "release";
}
def getVersionName() {
try {
def tmp = "${minecraft_version}-" + ("git describe --tags --dirty=-SNAPSHOT".execute().text.trim().substring(1).replaceFirst("(\\d+)-g[0-9a-f]+", "dev\$1"));
if (mod_version_postfix.isEmpty())
return tmp;
else
return tmp.replaceFirst("(.+?-[^\\-]+)(-)?", "\$1-${mod_version_postfix}\$2");
} catch(Exception e) {
println e
return 'UNKNOWN-VERSION'
}
}
def signJar(archivePath) {
if (project.hasProperty('keyStoreAlias') && project.hasProperty('keyStore') && project.hasProperty('keyStorePass')) {
ant.signjar(
jar: archivePath,
alias: project.keyStoreAlias,
keystore: project.keyStore,
storepass: project.keyStorePass,
preservelastmodified: true
)
} else {
println 'WARNING!!!\tCannot sign jar!'
}
}
def MainDirResources = fileTree(dir: file('.'), includes: ['README.md', 'LICENSE', 'CHANGELOG.md'])
def jsonPatterns = ["mcmod.info", "**/*.json", "**/*.mcmeta", "**/*.cf", "**/*.ctx"]
version = getVersionName()
group = "com.space.extended" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "SpacePackExtended"
allprojects {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
minecraft {
version = "${minecraft_version}-${forge_version}"
runDir = "run"
replace '${version}', project.version
mappings = mapping_version
useDepAts = true
}
lombok {
version = "1.16.10"
sha256 = "7e9079406585c67fe25f607c34b17fbed48da0a9bceb15c09a558444cefcef0e"
}
task delombok(type: DelombokTask) {
args("src/main/java", "-d", "build/sources/delomboked/java")
}
task formatJson {
doLast {
sourceSets.main.resources.srcDirs.each {
dir -> fileTree(dir: dir, includes: jsonPatterns).each {
File file -> file.text = JsonOutput.prettyPrint(file.text) + "\n"
}
}
}
}
sourceMainJava {
source = sourceSets.main.allSource
}
processResources {
// this will ensure that this task is redone when the versions change.
inputs.property "version", project.version
inputs.property "mcversion", project.minecraft.version
// replace stuff in mcmod.info, nothing else
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
// replace version and mcversion
expand 'version':project.version, 'mcversion':project.minecraft.version
}
// copy everything else, thats not the mcmod.info
from(sourceSets.main.resources.srcDirs) {
exclude 'mcmod.info'
}
from MainDirResources
// Minify json resources
doLast {
fileTree(dir: outputs.files.asPath, includes: jsonPatterns).each {
File file -> file.text = JsonOutput.toJson(new JsonSlurper().parse(file))
}
}
}
task showVersion {
description "Displays the current version"
group "help"
compileJava.dependsOn showVersion
deobfCompileDummyTask.dependsOn showVersion
extractMcpMappings.dependsOn showVersion
doLast {
println version
def versionFile = new File(buildDir, '.version');
versionFile.getParentFile().mkdirs();
versionFile.text = version;
}
outputs.upToDateWhen { false }
}
task gitTag {
description "Tags the current version in git. Specify the version by passing \"-PtagVersion=version\""
group "help"
doLast {
def tagVersion
if ( project.hasProperty("tagVersion") ) {
tagVersion = project.tagVersion
} else {
tagVersion = "v" + version.split("-")[1]
}
exec {
executable "git"
args "tag", "-a", tagVersion, "-m", getChangelog()
}
}
}
jar {
doLast {
if (!gradle.taskGraph.hasTask(reobfJar)) {
signJar(jar)
}
}
}
reobfJar {
doLast {
signJar(jar)
}
}
task deobfJar(type: Jar) {
from sourceSets.main.output
classifier = 'deobf'
doLast {
signJar(deobfJar.archivePath)
}
}
sourceJar {
doLast {
signJar(sourceJar.archivePath)
}
}
artifacts {
archives jar
archives deobfJar
archives sourceJar
}
uploadArchives {
repositories {
mavenDeployer {
if (project.hasProperty("local_maven")) {
repository(url: "file://${local_maven}")
pom {
groupId = project.group
version = project.version
artifactId = project.archivesBaseName
project {
name project.archivesBaseName
packaging "jar"
description "Space Pack Extended"
// url "https://github.com/BrainStone/brainstone"
issueManagement {
system "github"
// url "https://github.com/BrainStone/brainstone/issues"
}
licenses {
license {
name "License"
// url "https://raw.githubusercontent.com/BrainStone/brainstone/master/LICENSE"
distribution "repo"
}
}
developers {
developer {
id "norzeteus"
name "Norzeteus"
roles {
role "owner"
role "developer"
}
}
developer {
id "brainstone"
name "The_BrainStone"
roles {
role "developer"
}
}
}
}
}
}
}
}
}
curseforge {
apiKey = project.hasProperty("curseForgeApiKey")? project.curseForgeApiKey : "empty"
project {
id = "252607"
changelog = file("CHANGELOG.md")
changelogType = "markdown"
releaseType = getVersionType()
addGameVersion "${minecraft_version}"
addGameVersion "1.12.1"
addGameVersion "Java 8"
mainArtifact(jar) {
displayName = jar.archiveName.replace(".jar", "")
}
addArtifact(deobfJar) {
displayName = deobfJar.archiveName.replace(".jar", "")
changelog = "*This is a file for mod developers. If you don't know what to do with it, don't use it!*"
}
addArtifact(sourceJar) {
displayName = sourceJar.archiveName.replace(".jar", "")
changelog = "*This is a file for mod developers. If you don't know what to do with it, don't use it!*"
}
}
}