Extract widener definition into a widener.gradle.kts plugin

This commit is contained in:
2026-06-11 20:38:33 +02:00
parent aa66b3dc83
commit 2bc164c1b0
8 changed files with 148 additions and 95 deletions
+3 -42
View File
@@ -19,6 +19,7 @@
plugins {
steamwar.java
widener
}
tasks.compileJava {
@@ -42,45 +43,6 @@ tasks.withType<Test>().configureEach {
jvmArgs("--add-exports", "java.base/jdk.internal.misc=ALL-UNNAMED")
}
// ─── Collect all .accesswidener files from this plugin's resources ────────────
val accessWidenerFiles: FileCollection = fileTree("src/") {
include("**/*.accesswidener")
}
val paperJarProvider: Provider<File> = provider {
val dep = libs.nms.get()
configurations["compileClasspath"].resolvedConfiguration.resolvedArtifacts.first { artifact ->
artifact.moduleVersion.id.module.group == dep.module.group && artifact.moduleVersion.id.module.name == dep.module.name
}.file
}
// ─── Widen the Paper dev JAR so the IDE / javac see the patched access ────────
val widenedJar by tasks.registering(JavaExec::class) {
description = "Produces a widened copy of the Paper dev JAR for compile-time use."
group = "widener"
// Re-run whenever the .accesswidener files change
inputs.file(paperJarProvider)
inputs.files(accessWidenerFiles)
val output = layout.buildDirectory.file("widened/paper-widened.jar")
outputs.file(output)
classpath = project(":AccessWidener").tasks.named<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar>("shadowJar").get().outputs.files
mainClass.set("de.steamwar.Main")
doFirst {
args = buildList {
add(paperJarProvider.get().absolutePath)
add(output.get().asFile.absolutePath)
addAll(accessWidenerFiles.map { it.absolutePath })
}
}
dependsOn(":AccessWidener:shadowJar")
}
dependencies {
compileOnly(libs.classindex)
annotationProcessor(libs.classindex)
@@ -92,7 +54,6 @@ dependencies {
compileOnly(libs.paperapi)
compileOnly(libs.nms)
compileOnly(files(widenedJar))
compileOnly(libs.authlib)
compileOnly(libs.datafixer)
compileOnly(libs.netty)
@@ -102,6 +63,6 @@ dependencies {
implementation(libs.anvilgui)
}
tasks.compileJava {
dependsOn(widenedJar)
widener {
fromCatalog(libs.nms)
}