This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
forked from CorgiTaco-Archive/lazydfu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
274 lines (230 loc) · 9.78 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
/*
* GradleWorks for ForgeGradle 5
* Written by Jonathing
* Version 4.0.0-beta.3
*
* What was once just an effort to make life easier is now a fully-fledged buildscript that does almost all of the work
* for you! The only things you will need to take care of yourself are dependencies, but that shouldn't be too big of a
* deal. Anything you'll most likely ever need to change can be found in gradle.properties. Enjoy!
*/
import net.minecraftforge.gradle.common.util.ModConfig
// Detects if the OS is macOS.
static boolean isMacOS() {
def osProp = System.properties['os.name'].toLowerCase()
return osProp.contains('darwin') || osProp.contains('osx') || osProp.contains('mac')
}
// Detects if the OS is Windows.
static boolean isWindows() {
def osProp = System.properties['os.name'].toLowerCase()
return osProp.contains('windows')
}
// Detects if GradleWorks should use Mixin.
boolean isUsingMixin() {
return project.hasProperty('mixin_version')
}
// Whether or not to use FML only (REMINDER: YOU ARE GIVEN NO SUPPORT FOR THIS).
boolean usingFMLOnly() {
return project.hasProperty('use_fmlonly') && Boolean.parseBoolean(use_fmlonly)
}
// Buildscript setup (DO NOT EDIT!!!)
buildscript {
repositories {
// Minecraft Forge Maven
maven { url 'https://maven.minecraftforge.net' }
// SpongePowered Maven
maven { url 'https://repo.spongepowered.org/maven' }
// ParchmentMC Maven
maven { url 'https://maven.parchmentmc.org' }
// Maven Central
mavenCentral()
}
dependencies {
// Minecraft Forge ForgeGradle
classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '5.1.+', changing: true
// SpongePowered MixinGradle
classpath group: 'org.spongepowered', name: 'mixingradle', version: '0.7.+', changing: true
// ParchmentMC Librarian
classpath group: 'org.parchmentmc', name: 'librarian', version: '1.+', changing: true
}
}
println('GradleWorks for ForgeGradle 5')
println('Written by Jonathing')
println('Version 4.0.0-beta.3')
// ForgeGradle - The heart and soul of the buildscript and the development environment.
apply plugin: 'net.minecraftforge.gradle'
// MixinGradle - Adds Mixin support to the development environment.
if (isUsingMixin()) {
if (!project.extensions.findByName('eclipse')) {
println()
}
apply plugin: 'org.spongepowered.mixin'
}
// Librarian - Adds Parchment support to the development environment.
apply plugin: 'org.parchmentmc.librarian.forgegradle'
// Eclipse - Adds compatibility for Eclipse workspaces.
apply plugin: 'eclipse'
// Signing - Adds the ability to sign jars.
apply plugin: 'signing'
// Maven Publishing - Used to be able to publish to maven repositories.
apply plugin: 'maven-publish'
// Gets a file from a parent directory and folder/file names.
// Accounts for windows backslashes because I'm paranoid as hell.
File getFile(File parent, String... paths) {
StringBuilder builder = new StringBuilder()
builder.append(parent)
for (String path : paths) {
builder.append('/')
builder.append(path)
}
return file(builder.toString().replace('/', isWindows() ? '\\' : '/'))
}
// Get the mod version from gradle.properties.
version = mod_version
// Get the mod group from gradle.properties.
group = mod_group
// Get the archives base name from the mod id and the Minecraft version.
archivesBaseName = String.format('%s-%s', mod_id, mc_version)
// this variable points to where the latest built file is placed for usage in publish.gradle.
project.ext.reobfFile = getFile(buildDir, 'libs', "${archivesBaseName}-${version}.jar".toString())
// This file contains additional instructions for signing builds of this mod (see the file for more details).
apply from: 'signing.gradle'
// This file contains additional instructions for publishing builds of this mod to maven repositories (commented out by default, see the file for more details).
apply from: 'publish.gradle'
// Ensure that the IDE knows that this project is for Java 16 (or at the least, SDK level 16) and nothing else.
java.toolchain.languageVersion = JavaLanguageVersion.of(16)
// This section prints out the Java, Minecraft, and Mod info just to double check all the values are correct.
// It is printed on every build, so make sure you double check!
println()
println('Java Information')
printf('- Java: %s%n', System.getProperty('java.version'))
printf('- JVM: %s (%s)%n', System.getProperty('java.vm.version'), System.getProperty('java.vendor'))
printf('- Arch: %s%n', System.getProperty('os.arch'))
println()
println('Minecraft Information')
printf('- Minecraft: %s%n', mc_version)
printf('- Minecraft Forge: %s%n', forge_version)
printf('- Mappings: %s %s%n', mappings_version, mappings_channel)
println()
println('Mod Information')
printf('- ID: %s%n', mod_id)
printf('- Name: %s%n', mod_name)
printf('- Version: %s%n', version)
println()
// Any repositories for dependencies go here. Feel free to add to them as needed.
repositories {
// CurseMaven
maven {
url 'https://www.cursemaven.com'
content {
includeGroup 'curse.maven'
}
}
}
// Minecraft setup
minecraft {
// Mappings to use for the project. See default MDK for mappings instructions.
mappings channel: mappings_channel, version: mappings_version
// The access transformer file for the project.
// GradleWorks only tells ModDev we're using an AT if the file exists. If you don't need it, don't make it.
File atFile = getFile(projectDir, 'src', 'main', 'resources', 'META-INF', 'accesstransformer.cfg')
if (atFile.exists()) {
accessTransformer = atFile
}
// Run configurations
runs {
// All run configurations
all {
// Process non-mod libraries for 1.17.1.
lazyToken('minecraft_classpath') {
configurations.library.copyRecursive().resolve().collect { it.absolutePath }.join(File.pathSeparator)
}
// The directory for Minecraft to run in.
workingDirectory getFile(projectDir, 'run')
// Logging markers for Forge. See default MDK for instructions.
property 'forge.logging.markers', 'REGISTRIES'
// Console logging level (debug by info, change to debug if you need debug logging).
property 'forge.logging.console.level', 'info'
// Tells the mod if it is running in an IDE (must be configured in your project, but not required).
property "${mod_id}.iside".toString(), 'true'
// Add the mod's main source set to the total mods in the run configuration.
ModConfig modConfig = new ModConfig(project, mod_id)
modConfig.source(sourceSets.main)
mods.add(modConfig)
}
// Client run configuration
client {
// The client run configuration does not need any additional properties.
// All of them are defined in the "all" closure. If you'd like to add some of your own, feel free.
}
// Server run configuration
server {
// Additional arguments exclusive to the server (nogui by default, separated by ",").
args 'nogui'
}
// Data run configuration
data {
// Additional arguments exclusive to data generation (do NOT change these unless necessary).
args '--mod', mod_id, '--all', '--output', getFile(projectDir, 'src', 'generated', 'resources'), '--existing', getFile(projectDir, 'src', 'main', 'resources')
// Tells the mod if it is running datagen (must be configured in your project, but not required).
property "${mod_id}.datagen".toString(), 'true'
// Workaround for https://github.com/MinecraftForge/ForgeGradle/issues/690
// Written by Shadew
if (isMacOS()) {
jvmArg('-XstartOnFirstThread')
}
}
}
}
// Additional settings for the resources source set.
sourceSets.main.resources {
// Include resources generated by data generators.
srcDir getFile(projectDir, 'src', 'generated', 'resources')
}
if (isUsingMixin()) {
// MixinGradle settings
mixin {
// Add the refmap to the built JAR file.
add sourceSets.main, "${mod_id}.refmap.json".toString()
// Add the mixin config JSON file to run configs and the built JAR's Manifest.
config "${mod_id}.mixins.json".toString()
// Enable debug logging for mixins in the run configs.
debug.export = true
}
}
// Additional configuration for non-mod dependencies.
configurations {
library
implementation.extendsFrom(library)
}
// Dependencies to use in this project.
dependencies {
// Minecraft Forge
String toolchain = 'forge'
if (usingFMLOnly()) {
toolchain = 'fmlonly'
}
minecraft "net.minecraftforge:${toolchain}:${mc_version}-${forge_version}".toString()
// Mixin processor
if (isUsingMixin()) {
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor".toString()
}
// Lazy DataFixerUpper(LazyDFU) [FORGE]
// TODO Use custom 1.17 build of LazyDFU in the future
if (project.hasProperty('lazydfu_file_id')) {
// runtimeOnly fg.deobf("curse.maven:lazy-dfu-forge-460819:${lazydfu_file_id}".toString())
}
}
// Attributes to include in the built jar file.
jar {
manifest {
attributes([
'Specification-Title' : mod_id,
'Specification-Vendor' : mod_author,
'Specification-Version' : '1',
'Implementation-Title' : project.name,
'Implementation-Version' : archiveVersion.getOrElse(version),
'Implementation-Vendor' : mod_author,
'Implementation-Timestamp': new Date().format('yyyy-MM-dd\'T\'HH:mm:ssZ')
])
}
}