/
build.gradle
333 lines (292 loc) · 8.66 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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
import se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask
buildscript {
repositories {
maven { url = 'https://files.minecraftforge.net/maven' }
mavenCentral()
}
// This is only here while FG is under active development
configurations.classpath {
resolutionStrategy {
cacheDynamicVersionsFor 10, 'seconds'
cacheChangingModulesFor 0, 'seconds'
}
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
}
}
plugins {
id 'java'
id 'eclipse'
id 'idea'
id 'com.matthewprenger.cursegradle' version '1.4.0'
id 'se.bjurr.gitchangelog.git-changelog-gradle-plugin' version '1.71.4'
}
apply plugin: 'net.minecraftforge.gradle'
apply from: 'buildtools/ColoredOutput.gradle'
//adds the build number to the end of the version string if on a build server
String build_number = System.getenv().BUILD_NUMBER
if (build_number == null) {
build_number = '9999'
}
String semver = "${version_major}.${version_minor}.${version_patch}"
// these two are required for the java plugin to generate jar files with a version
version = "${semver}.${build_number}"
group = 'mezz.jei' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
sourceSets {
api
main {
compileClasspath += sourceSets.api.output
runtimeClasspath += sourceSets.api.output
resources {
srcDir 'src/generated/resources'
}
}
test {
compileClasspath += sourceSets.api.output
runtimeClasspath += sourceSets.api.output
}
}
configurations {
apiImplementation.extendsFrom(implementation)
apiRuntimeOnly.extendsFrom(runtimeOnly)
}
java.toolchain.languageVersion = JavaLanguageVersion.of(8)
dependencies {
minecraft([
group : "${project.forgegroup}",
name : 'forge',
version: "${project.mcversion}-${project.forgeversion}"
])
testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.2"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:5.7.2"
}
minecraft {
mappings channel: 'official', version: project.mcversion
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')
runs {
client {
property 'forge.logging.console.level', 'debug'
workingDirectory file('run')
mods {
jei.sources((SourceSet[]) [sourceSets.main, sourceSets.api])
}
}
server {
property 'forge.logging.console.level', 'debug'
workingDirectory file('run')
mods {
jei.sources((SourceSet[]) [sourceSets.main, sourceSets.api])
}
}
data {
property 'forge.logging.console.level', 'debug'
workingDirectory file('run')
args '--mod', 'jei', '--all', '--output', file('src/generated/resources/')
mods {
jei.sources((SourceSet[]) [sourceSets.main, sourceSets.api])
}
}
}
}
def replaceResources = tasks.register("replaceResources", Copy) {
it.outputs.upToDateWhen { false }
//Copy it into the build dir
it.from(sourceSets.main.resources) {
include "META-INF/mods.toml"
expand 'version': version, 'mc_version': minecraft_version_range, 'forge_version': forge_version_range
}
it.into "$buildDir/resources/main/"
}
processResources {
duplicatesStrategy(DuplicatesStrategy.FAIL)
exclude('META-INF/mods.toml')
configure { finalizedBy(replaceResources) }
}
classes.configure {
dependsOn(replaceResources)
}
javadoc {
source = [sourceSets.main.allJava, sourceSets.api.allJava]
// prevent java 8's strict doclint for javadocs from failing builds
options.addStringOption('Xdoclint:none', '-quiet')
}
task makeChangelog(type: se.bjurr.gitchangelog.plugin.gradle.GitChangelogTask) {
file = file('changelog.html')
untaggedName = "Current release ${project.version}"
fromCommit = '2fe051cf727adce1be210a46f778aa8fe031331e'
toRef = 'HEAD'
templateContent = file('changelog.mustache').getText('UTF-8')
}
curseforge {
apiKey = project.findProperty('curseforge_apikey') ?: '0'
project {
id = curse_project_id
changelog = file('changelog.html')
changelogType = 'html'
releaseType = 'beta'
}
}
afterEvaluate {
tasks.curseforge238222.dependsOn makeChangelog
}
configurations.all {
// lwjgl:3.3.0 and java-objc-bridge:1.1 have support for apple silicon
resolutionStrategy {
force "ca.weblite:java-objc-bridge:1.1"
force "org.lwjgl:lwjgl-glfw:3.3.0"
force "org.lwjgl:lwjgl-jemalloc:3.3.0"
force "org.lwjgl:lwjgl-openal:3.3.0"
force "org.lwjgl:lwjgl-opengl:3.3.0"
force "org.lwjgl:lwjgl-stb:3.3.0"
force "org.lwjgl:lwjgl-tinyfd:3.3.0"
force "org.lwjgl:lwjgl:3.3.0"
}
}
import net.minecraftforge.gradle.common.util.Utils
import net.minecraftforge.gradle.common.util.VersionJson
import org.apache.commons.io.FileUtils
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.StandardCopyOption
import java.nio.file.Path
task extractLwjglNatives(type: ExtractLwjglNatives) {
meta = tasks.extractNatives.meta
output = tasks.extractNatives.output
}
extractNatives {
finalizedBy extractLwjglNatives
}
// Extract LWJGL natives from the native JARs provided by LWJGL on Maven Central
abstract class ExtractLwjglNatives extends DefaultTask {
@InputFile
abstract RegularFileProperty getMeta();
@OutputDirectory
abstract DirectoryProperty getOutput();
@TaskAction
void run() {
def os = VersionJson.OS.current
def osName = os == VersionJson.OS.OSX ? 'macos' : os.name
def classifier = osName
def arch = System.getProperty('os.arch')
if (['aarch64', 'arm64'].contains(arch)) {
classifier += '-arm64'
}
def json = Utils.loadJson(meta.getAsFile().get(), VersionJson.class)
json.getNatives()
.stream()
.filter {it.path.startsWith('org/lwjgl') }
.each {
def version = '3.3.0'
def type = it.path.split(/\//)[2]
def path = "org/lwjgl/$type/$version/$type-$version-natives-${classifier}.jar"
def target = Utils.getCache(getProject(), 'libraries', path)
def url = new URL("https://repo1.maven.org/maven2/$path")
if (!target.exists()) {
if (!target.getParentFile().exists()) {
target.getParentFile().mkdirs()
}
FileUtils.copyURLToFile(url, target)
}
def rootPath = FileSystems.newFileSystem(target.toPath(), null).getPath('/')
Files.walk(rootPath.resolve(osName))
.filter { Files.isRegularFile(it) }
.each {
def outputFile = getOutput().get().getAsFile()
def file = new File("${outputFile.toPath()}${it}")
def filePath = file.toPath()
if (!file.exists()) {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs()
}
}
Files.copy(it, filePath, StandardCopyOption.REPLACE_EXISTING)
}
}
}
}
jar {
from sourceSets.main.output
from sourceSets.api.output
manifest.attributes([
'Specification-Title' : 'Just Enough Items',
'Specification-Vendor' : 'mezz',
'Specification-Version' : "${semver}",
'Implementation-Title' : project.name,
'Implementation-Version' : "${project.version}",
'Implementation-Vendor' : 'mezz',
'Implementation-Timestamp': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ"),
])
finalizedBy 'reobfJar'
}
task javadocJar(type: Jar, dependsOn: javadoc) {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}
task sourcesJar(type: Jar) {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveClassifier.set('sources')
from sourceSets.main.allJava
from sourceSets.api.allJava
}
task apiJar(type: Jar) {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveClassifier.set('api')
from sourceSets.api.output
afterEvaluate { finalizedBy reobfApiJar }
// TODO: when FG bug is fixed, remove allJava from the api jar.
// https://github.com/MinecraftForge/ForgeGradle/issues/369
// Gradle should be able to pull them from the -sources jar.
from sourceSets.api.allJava
}
task deobfJar(type: Jar) {
duplicatesStrategy(DuplicatesStrategy.FAIL)
archiveClassifier.set('deobf')
from sourceSets.main.output
from sourceSets.api.output
}
artifacts {
archives javadocJar
archives sourcesJar
archives apiJar
archives deobfJar
}
reobf {
apiJar { classpath.from(sourceSets.api.compileClasspath) }
jar { classpath.from(sourceSets.main.compileClasspath) }
}
task reobf {
dependsOn reobfJar
dependsOn reobfApiJar
}
task uploadJars(dependsOn: build) {
description = 'Uploads JARs'
if (project.hasProperty('local_maven')) {
apply plugin: 'maven-publish'
publishing {
publications { PublicationContainer publicationContainer ->
publicationContainer.register("maven", MavenPublication) { MavenPublication publication ->
publication.artifacts = [apiJar, jar, javadocJar, deobfJar, sourcesJar]
}
}
repositories {
maven {
url("file://${local_maven}")
}
}
}
}
}
idea {
module {
for (String exclude in ['run', 'out', 'logs']) {
excludeDirs += file(exclude)
}
}
}
test {
useJUnitPlatform()
include 'mezz/jei/**'
exclude 'mezz/jei/lib/**'
}