-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.gradle
289 lines (255 loc) · 9.24 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
import groovy.json.JsonSlurper
import groovy.transform.EqualsAndHashCode
import groovy.transform.TupleConstructor
plugins {
id 'java-gradle-plugin'
id 'maven-publish'
id 'net.neoforged.gradleutils' version '3.0.0'
id 'com.gradle.plugin-publish' version '1.2.1'
id 'com.gradleup.shadow' version '8.3.0'
}
group = 'net.neoforged'
base {
archivesName = "moddev-gradle"
}
gradleutils.version {
tags {
label = "beta"
cleanMarkerLabel = "stable"
}
branches.suffixBranch()
}
project.version = gradleutils.version
logger.lifecycle("ModDevGradle version ${gradleutils.version}")
changelog {
from '2.0'
// For fine-grained changelog publication control.
// Otherwise, the changelog would get published alongside the "xxx.gradle.plugin" artifact too which we don't want.
disableAutomaticPublicationRegistration()
}
if (System.getenv('GPP_KEY')) {
project.ext {
set('gradle.publish.key', System.getenv('GPP_KEY'))
set('gradle.publish.secret', System.getenv('GPP_SECRET'))
}
}
repositories {
exclusiveContent {
forRepository {
maven {
name = "Fabric"
url = "https://maven.fabricmc.net/"
}
}
filter {
includeModule("net.fabricmc", "fabric-loom-native")
}
}
maven {
name = "NeoForged"
url = "https://maven.neoforged.net/releases"
content {
includeGroup "net.neoforged"
}
}
mavenCentral()
gradlePluginPortal()
}
sourceSets {
java8
main {
java {
srcDirs += project.file('src/generated/java')
}
compileClasspath += java8.output
runtimeClasspath += java8.output
}
}
configurations {
// Configuration for all dependencies that we want shaded.
shaded
// Place shaded dependencies into `compileOnly` so that they do not leak into our publications' dependencies.
compileOnly.extendsFrom shaded
testCompileOnly.extendsFrom shaded
testRuntimeOnly.extendsFrom shaded
shadowRuntimeElements {
// `shadowRuntimeElements` is what gets published.
// We want it to contain the non-shaded runtime dependencies.
it.extendsFrom implementation, runtimeOnly
}
// Change the Category attribute so that includeBuilds don't select the default `runtimeElements` configuration.
// The Plugin Publish plugin already disables Maven publication of this configuration automatically.
runtimeElements {
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, "not-wanted-publication"))
}
}
changelog {
canBeResolved = false
canBeConsumed = true
attributes {
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION))
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, "changelog"))
}
project.components.findByName("java").addVariantsFromConfiguration(it) { }
}
}
dependencies {
compileOnly gradleApi()
compileOnly "com.intellij:annotations:9.0.4"
testCompileOnly "com.intellij:annotations:9.0.4"
shaded "com.google.code.gson:gson:2.11.0"
implementation "gradle.plugin.org.jetbrains.gradle.plugin.idea-ext:gradle-idea-ext:1.1.8"
shaded "net.neoforged:EclipseLaunchConfigs:0.1.11"
shaded "net.neoforged:VscLaunchConfigs:1.0.8"
shaded("net.neoforged:JarJarMetadata:0.4.2") {
exclude group: 'org.slf4j'
}
java8CompileOnly gradleApi()
testImplementation(enforcedPlatform("org.junit:junit-bom:5.10.3"))
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testImplementation 'org.junit.jupiter:junit-jupiter-params'
testImplementation 'org.assertj:assertj-core:3.26.0'
testImplementation gradleTestKit()
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
withSourcesJar()
}
jar {
archiveClassifier = 'slim'
from sourceSets.java8.output
}
shadowJar {
archiveClassifier = "" // Required for the Plugin Publish Plugin to publish this jar
from sourceSets.java8.output
configurations = [project.configurations.shaded]
enableRelocation = true
relocationPrefix = "net.neoforged.moddev.shadow"
}
assemble.dependsOn shadowJar
tasks.named("compileJava8Java").configure {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(8)
}
}
javadoc {
options.addBooleanOption("Xdoclint:all,-missing", true)
}
// This is a shameless ripoff from Fabric Loom:
// https://github.com/FabricMC/fabric-loom/blob/dev/1.6/build.gradle
// Need to tweak this file to pretend we are compatible with j8 so the bootstrap will run.
tasks.withType(GenerateModuleMetadata).configureEach {
doLast {
def file = outputFile.get().asFile
def metadata = new groovy.json.JsonSlurper().parseText(file.text)
metadata.variants.each {
it.attributes["org.gradle.jvm.version"] = 8
}
file.text = groovy.json.JsonOutput.toJson(metadata)
}
}
gradlePlugin {
website = 'https://github.com/neoforged/ModDevGradle'
vcsUrl = 'https://github.com/neoforged/ModDevGradle.git'
plugins {
moddev {
id = 'net.neoforged.moddev'
implementationClass = 'net.neoforged.moddevgradle.boot.ModDevPlugin'
displayName = "NeoForge Mod Development Plugin"
description = "This plugin helps you create Minecraft mods using the NeoForge platform"
tags = ["minecraft", "neoforge", "java", "mod"]
}
repositories {
id = 'net.neoforged.moddev.repositories'
implementationClass = 'net.neoforged.moddevgradle.boot.RepositoriesPlugin'
displayName = "NeoForge Mod Development Repositories Plugin"
description = "This plugin adds the repositories needed for developing Minecraft mods. It is applied automatically by the moddev plugin, but can be applied manually in settings.gradle to make use of Gradle dependency management."
tags = ["minecraft", "neoforge", "java", "mod"]
}
}
}
test {
useJUnitPlatform()
}
artifacts {
changelog(createChangelog.outputFile) {
builtBy(createChangelog)
setClassifier("changelog")
setExtension("txt")
}
}
publishing {
repositories {
maven {
name = 'NeoForge'
if (System.getenv('MAVEN_USER') && System.getenv('MAVEN_PASSWORD')) {
it.url = "https://maven.neoforged.net/releases/"
it.authentication {
it.create('basic', BasicAuthentication)
}
it.credentials { credentials ->
credentials.username = System.getenv('MAVEN_USER')
credentials.password = System.getenv('MAVEN_PASSWORD')
}
} else {
it.url = 'file://' + file("repo").getAbsolutePath()
}
}
}
}
// By default, the testkit will use sourceSets.main.runtimeClasspath (= the configuration + the source set's outputs).
// That contains the non-shaded plugin classes, and does not contain our shaded dependencies!
// Instead, let's use the shadow jar and configurations.runtimeClasspath.
tasks.withType(PluginUnderTestMetadata).configureEach {
it.pluginClasspath.setFrom tasks.shadowJar, configurations.runtimeClasspath
it.inputs.file(shadowJar.archiveFile)
}
abstract class GenerateRepoFilter extends DefaultTask {
@OutputFile
abstract RegularFileProperty getOutput()
@EqualsAndHashCode
@TupleConstructor
static class Artifact implements Comparable<Artifact> {
String group, module
@Override
int compareTo(Artifact o) {
final groups = this.group <=> o.group
if (groups) return groups
return this.module <=> o.module
}
}
@TaskAction
void run() {
final Set<Artifact> artifacts = []
final json = new JsonSlurper()
final manifest = json.parse('https://piston-meta.mojang.com/mc/game/version_manifest_v2.json'.toURL())
manifest.versions.each { ver ->
final version = json.parse((ver.url as String).toURL())
version.libraries.each { lib ->
final location = (lib.name as String).split(':', 3)
artifacts.add(new Artifact(location[0], location[1]))
}
}
final artifactList = artifacts.toList()
Collections.sort(artifactList)
final clazz = """
package net.neoforged.moddevgradle.internal.generated;
public class MojangRepositoryFilter {
public static void filter(org.gradle.api.artifacts.repositories.RepositoryContentDescriptor filter) {
${artifactList.collect { " filter.includeModule(\"${it.group}\", \"${it.module}\");" }.join('\n')}
}
}
"""
output.get().asFile.write(clazz)
}
}
tasks.register('generateMojangRepositoryFilter', GenerateRepoFilter) {
output = project.file('src/generated/java/net/neoforged/moddevgradle/internal/generated/MojangRepositoryFilter.java')
group = 'build'
description = "Generates a repository filter for Mojang's libraries maven"
}