forked from neoforged/NeoForge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
135 lines (116 loc) · 4.7 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
import java.util.regex.Matcher
import java.util.regex.Pattern
plugins {
id 'net.neoforged.gradleutils' version '3.0.0-alpha.10' apply false
id 'com.diffplug.spotless' version '6.22.0' apply false
id 'net.neoforged.licenser' version '0.7.2' apply false
}
apply plugin: 'net.neoforged.gradleutils'
ext.isPreReleaseVersion = project.minecraft_version.contains("w") || project.minecraft_version.contains("-")
if (isPreReleaseVersion) {
project.version = "${project.neoforge_snapshot_next_stable}.0-alpha.${project.minecraft_version}.${(new Date()).format('yyyyMMdd.HHmmss', TimeZone.getTimeZone('UTC'))}"
} else {
gradleutils.version {
minecraftVersion project.minecraft_version
versionPrefix = null // Reset version prefix, which is set by prev. line
tags {
label = 'beta'
cleanMarkerLabel = 'stable'
}
branches {
suffixBranch = true
}
}
changelog {
from '20.5'
disableAutomaticPublicationRegistration()
}
project.version = gradleutils.version.toString()
}
// Print version, generally useful to know - also appears on CI
System.out.println("NeoForge version ${project.version}")
allprojects {
version rootProject.version
group 'net.neoforged'
repositories {
mavenLocal()
}
}
subprojects {
apply plugin: 'java'
java.toolchain.languageVersion.set(JavaLanguageVersion.of(project.java_version))
}
apply plugin: 'com.diffplug.spotless'
apply plugin: 'net.neoforged.licenser'
repositories {
mavenCentral()
}
// Put licenser here otherwise it tries to license all source sets including decompiled MC sources
license {
header = file('codeformat/HEADER.txt')
skipExistingHeaders = true
tasks {
neoforge {
// Add all NeoForge sources
files.from rootProject.fileTree("src", {
include "**/*.java"
})
}
}
}
// Put spotless here because it wants the files to live inside the project root
spotless {
java {
target rootProject.fileTree("src", {
include "**/*.java"
})
}
format 'patches', {
target rootProject.fileTree("patches")
custom 'noImportChanges', { String fileContents ->
if (fileContents.contains('+import') || fileContents.contains('-import')) {
throw new GradleException("Import changes are not allowed in patches!")
}
return fileContents
}
def interfaceChange = Pattern.compile('^[-+].*(implements|(interface.*extends)).*\$', Pattern.UNIX_LINES | Pattern.MULTILINE)
custom 'noInterfaceRemoval', { String fileContents ->
def interfaceChanges = fileContents.findAll(interfaceChange)
if (interfaceChanges.isEmpty()) return fileContents
String removalChange = ""
interfaceChanges.each { String change ->
if (change.startsWith('-')) {
//Skip the - and the ending brace
int implementsIndex = change.indexOf("implements")
if (implementsIndex == -1) implementsIndex = change.indexOf("extends")
//It should never still be -1 based on our initial matching regex, but if it does fail so we can figure out why
if (implementsIndex == -1) implementsIndex = 1
removalChange = change.substring(implementsIndex, change.length() - 1).trim()
} else if (!removalChange.isEmpty() && !change.contains(removalChange)) {
throw new GradleException("Removal of interfaces via patches is not allowed!")
} else {
removalChange = ""
}
}
if (!removalChange.isEmpty()) {
throw new GradleException("Removal of interfaces via patches is not allowed!")
}
return fileContents
}
//Trim any trailing whitespace from patch additions
def trailingWhitespace = Pattern.compile('^\\+.*[ \t]+\$', Pattern.UNIX_LINES | Pattern.MULTILINE)
custom 'trimTrailingWhitespacePatches', { String fileContents ->
Matcher matcher = trailingWhitespace.matcher(fileContents)
StringBuilder sb = new StringBuilder()
while (matcher.find()) {
matcher.appendReplacement(sb, matcher.group().trim())
}
matcher.appendTail(sb)
return sb.toString()
}
bumpThisNumberIfACustomStepChanges(3)
}
}
apply from: rootProject.file('buildscript/spotless-rules.gradle')
apply from: rootProject.file('buildscript/generate-package-infos.gradle')
apply from: rootProject.file('buildscript/apply-all-formatting.gradle')