-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
256 lines (220 loc) · 7.62 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
import net.minecraftforge.gradle.common.tasks.SignJar
buildscript {
repositories {
maven { url = 'https://maven.minecraftforge.net' }
mavenCentral()
maven {url 'https://maven.parchmentmc.org'}
maven {url 'https://repo.spongepowered.org/repository/maven-public/'}
}
dependencies {
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
classpath 'org.parchmentmc:librarian:1.+'
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
}
}
apply plugin: 'net.minecraftforge.gradle'
// Only edit below this line, the above code adds and enables the necessary things for Forge to be setup.
apply plugin: 'maven-publish'
apply plugin: 'org.parchmentmc.librarian.forgegradle'
apply plugin: 'org.spongepowered.mixin'
apply plugin: 'eclipse'
version = project.ce_version+makeVersionSuffix()
group = "malte0811.controlengineering"
archivesBaseName = "ControlEngineering"
String makeVersionSuffix() {
return System.getenv("GITHUB_ACTIONS") != null ? "-GH-" + System.getenv("GITHUB_RUN_NUMBER") : ""
}
sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = 17
sourceSets {
main {
resources {
srcDirs = [
"$rootDir/src/main/resources",
"$rootDir/src/generated/resources"
]
}
}
datagen {
compileClasspath += main.output + main.compileClasspath
runtimeClasspath += main.output + main.runtimeClasspath
}
}
def setupSourceSet(SourceSet sourceSet, String name) {
sourceSet.java {
srcDir 'src/' + name + '/java'
}
sourceSet.resources {
//Add the generated module resources
srcDirs += 'src/generated/resources'
//But exclude the cache of the generated data from what gets built
exclude '.cache'
}
}
def version_replacements = [
'mc_version': minecraft_version,
'ie_version': ie_version,
'ce_version': project.version,
'forge_version': forge_version,
]
processResources {
inputs.properties(version_replacements)
filesMatching("META-INF/mods.toml") {
expand version_replacements
}
exclude ".cache"
}
// When using "Run using IntelliJ" (the only option with well-working hotswapping) the used "resources" directory is
// different from the one used by gradle/the processResources task
task copyModsTomlForIntelliJ(type: Copy) {
from processResources.destinationDir
into "$projectDir/out/production/resources"
include "META-INF/mods.toml"
}
copyModsTomlForIntelliJ.dependsOn processResources
afterEvaluate {
// prepareRuns doesn't exist before afterEvaluate
prepareRuns.dependsOn copyModsTomlForIntelliJ
}
minecraft {
mappings channel: 'parchment', version: "${parchment_version}-${minecraft_version}"
// Default run configurations.
// These can be tweaked, removed, or duplicated as needed.
runs {
client {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', ''
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
mods {
controlengineering {
source sourceSets.main
}
}
}
server {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', ''
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
arg '-nogui'
mods {
controlengineering {
source sourceSets.main
}
}
}
data {
workingDirectory project.file('run')
// Recommended logging data for a userdev environment
property 'forge.logging.markers', ''
// Recommended logging level for the console
property 'forge.logging.console.level', 'debug'
ideaModule project.name+".datagen"
args '--mod', 'controlengineering', '--all', '--output', file('src/generated/resources/'), '--validate',
'--existing', sourceSets.main.resources.srcDirs[0], '--existing-mod', 'immersiveengineering'
mods {
controlengineering {
source sourceSets.main
source sourceSets.datagen
}
}
}
}
}
repositories {
maven { // JEI & Tinkers
name = 'DVS1 Maven FS'
url = 'https://dvs1.progwml6.com/files/maven'
}
maven {
name = "BlameJared"
url = "https://maven.blamejared.com/"
}
}
dependencies {
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"
runtimeOnly fg.deobf("blusunrize.immersiveengineering:ImmersiveEngineering:${ie_version}")
compileOnly fg.deobf("blusunrize.immersiveengineering:ImmersiveEngineering:${ie_version}:api")
datagenImplementation fg.deobf("blusunrize.immersiveengineering:ImmersiveEngineering:${ie_version}:datagen")
testImplementation('junit:junit:4.13')
}
def customGradle = rootProject.file('custom.gradle');
if (customGradle.exists()) {
apply from: customGradle;
}
def reobfFile = file("$buildDir/reobfJar/output.jar")
def reobfArtifact = artifacts.add('default', reobfFile) {
type 'jar'
builtBy 'reobfJar'
}
task signJar(type: SignJar, dependsOn: jar) {
onlyIf {
project.hasProperty('keyStore')
}
if (project.hasProperty('keyStore')) {
keyStore = project.keyStore
alias = project.storeAlias
storePass = project.storePass
keyPass = project.storePass
inputFile = jar.archivePath
outputFile = jar.archivePath
} else {
logger.warn("No key store found, not signing the output jar\n")
}
}
build.dependsOn signJar
afterEvaluate {
signJar.dependsOn reobfJar
}
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
task speedUpPreRun {
doLast {
for (String s : new String[]{"Client", "Server", "Data"}) {
ant.replace(
file: ".idea/runConfigurations/run"+s+".xml",
// prepareRunX is prepareRuns + compile, but compiling is already handled by IntelliJ
token: "prepareRun"+s,
value: "prepareRuns"
)
}
}
}
tasks.withType(Task) {
if (it.name == "genIntellijRuns") {
it.finalizedBy speedUpPreRun
} else if (it.name == "runServer") {
it.standardInput = System.in
}
}
//Minimize/optimize all png files, requires optipng on the PATH
// Credits: BrainStone
void minimizePNGFile(File file) {
long size = file.length()
exec {
executable "optipng"
args "-q", "-o7", "-zm1-9", "-strip", "all", file
}
long newSize = file.length()
if (newSize < size) {
System.out.format("Reduced File size of %s from %d bytes to %d bytes (reduced by %.2f%%)\n",
file, size, newSize, ((double) (size - newSize)) / ((double) size) * 100.0)
}
}
task optimizePng {
def pngPatterns = ["**/*.png"]
doLast {
//Ensure the logo is minimized (we add this file to each jar)
//Minimize any PNGs in the source sets
for (dir in sourceSets.main.resources.srcDirs) {
fileTree(dir: dir, includes: pngPatterns).each { minimizePNGFile(it) }
}
}
}