Skip to content

Commit

Permalink
Hide test information in distributed JARs
Browse files Browse the repository at this point in the history
  • Loading branch information
nea89o committed Jun 1, 2024
1 parent bcdba02 commit e24b2dd
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 54 deletions.
118 changes: 65 additions & 53 deletions modern/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,88 +1,100 @@
import xyz.wagyourtail.unimined.api.minecraft.task.RemapJarTask

plugins {
java
idea
`maven-publish`
alias(libs.plugins.unimined)
alias(libs.plugins.kotlin.jvm)
java
idea
`maven-publish`
alias(libs.plugins.unimined)
alias(libs.plugins.kotlin.jvm)
// alias(libs.plugins.kotlin.lombok)
alias(libs.plugins.dokka)
alias(libs.plugins.shadow)
alias(libs.plugins.dokka)
alias(libs.plugins.shadow)

}

unimined.minecraft {
version(libs.versions.mc.modern.get())
mappings {
intermediary()
yarn(libs.versions.yarn.build.get())
}

fabric {
loader(libs.versions.fabric.loader.get())
}
runs {
config("client") {
jvmArgs.add("-Dmoulconfig.testmod=true")
jvmArgs.add("-Dmoulconfig.warn.crash=false")
env.putAll(parseEnvFile(file(".env")))
}
}
version(libs.versions.mc.modern.get())
mappings {
intermediary()
yarn(libs.versions.yarn.build.get())
}

fabric {
loader(libs.versions.fabric.loader.get())
}
runs {
config("client") {
jvmArgs.add("-Dmoulconfig.testmod=true")
jvmArgs.add("-Dmoulconfig.warn.crash=false")
env.putAll(parseEnvFile(file(".env")))
}
}
}


java.toolchain.languageVersion.set(JavaLanguageVersion.of(17))

val shadowInclude by configurations.creating
dependencies {
implementation(project(":common"))
"modImplementation"(fabricApi.fabricModule("fabric-command-api-v2", libs.versions.fabric.api.get()))
"modImplementation"(fabricApi.fabricModule("fabric-resource-loader-v0", libs.versions.fabric.api.get()))
shadowInclude(project(":common", configuration = "singleFile"))
implementation(libs.libninepatch)
shadowInclude(libs.libninepatch)
implementation(project(":common"))
"modImplementation"(fabricApi.fabricModule("fabric-command-api-v2", libs.versions.fabric.api.get()))
"modImplementation"(fabricApi.fabricModule("fabric-resource-loader-v0", libs.versions.fabric.api.get()))
shadowInclude(project(":common", configuration = "singleFile"))
implementation(libs.libninepatch)
shadowInclude(libs.libninepatch)
}

tasks.shadowJar {
configurations = listOf(shadowInclude)
archiveClassifier.set("dev")
configurations = listOf(shadowInclude)
archiveClassifier.set("dev")
}

val remapJar by tasks.named("remapJar", RemapJarTask::class) {
archiveClassifier.set("")
dependsOn(tasks.shadowJar)
inputFile.set(tasks.shadowJar.flatMap { it.archiveFile })
archiveClassifier.set("")
dependsOn(tasks.shadowJar)
inputFile.set(tasks.shadowJar.flatMap { it.archiveFile })
}

tasks.processResources {
from(project(":common").tasks.processResources)
from(project(":common").tasks.processResources)
}

tasks.jar {
archiveClassifier.set("small")
dependsOn(tasks.processResources)
archiveClassifier.set("small")
dependsOn(tasks.processResources)
}

val sourcesJar by tasks.creating(Jar::class) {
from(sourceSets.main.get().allSource)
from(project(":common").sourceSets.getByName("main").allSource)
archiveClassifier.set("sources")
from(sourceSets.main.get().allSource)
from(project(":common").sourceSets.getByName("main").allSource)
archiveClassifier.set("sources")
}


tasks.withType(Jar::class){
this.filesMatching(listOf("fabric.mod.json")) {
filter {
if (it.contains("FabricMain")) ""
else it
}
}
exclude("io/github/notenoughupdates/moulconfig/test/**")
}

publishing {
publications {
create<MavenPublication>("maven") {
artifact(remapJar) {
classifier = ""
}
artifact(tasks.shadowJar) {
classifier = "named"
}
artifact(tasks["sourcesJar"]) {
classifier = "sources"
}
}
}
publications {
create<MavenPublication>("maven") {
artifact(remapJar) {
classifier = ""
}
artifact(tasks.shadowJar) {
classifier = "named"
}
artifact(tasks["sourcesJar"]) {
classifier = "sources"
}
}
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.util.*

class FabricMain : ModInitializer {
override fun onInitialize() {
if (System.getProperty("moulconfig.testmod") != "true") return
val config = ManagedConfig.create(File("config/moulconfig/test.json"), TestConfig::class.java)
ClientCommandRegistrationCallback.EVENT.register { a, b ->
a.register(literal("moulconfig").executes {
Expand Down Expand Up @@ -99,4 +100,4 @@ class FabricMain : ModInitializer {
var data: ObservableList<Element> =
ObservableList(ArrayList(Arrays.asList(Element("Test 1"), Element("Test 2"), Element("Test 3"))))
}
}
}
8 changes: 8 additions & 0 deletions modern/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@
"id": "moulconfig",
"schemaVersion": 1,
"version": "1.0.0",
"name": "Moulconfig",
"entrypoints": {
"main": [
"io.github.notenoughupdates.moulconfig.test.FabricMain"
]
},
"custom": {
"modmenu": {
"badges": [
"library"
]
}
}
}

0 comments on commit e24b2dd

Please sign in to comment.