From 8d2e150f05b49eb96fb37d40746accad503db077 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Thu, 17 Nov 2022 09:26:57 +0000 Subject: [PATCH] Various improvements to packaging This fixes several issues I had with consuming multi-loader CC:T in various upstream mods. - Include /all/ sources in the Forge/Fabric jar. Before it was just the common classes, and not the core or API. - Use some Gradle magic to remove superfluous dependencies from the POM file. Also make sure Cobalt and Netty are present as dependencies. - Start using minimize() in our shadow jar config again. --- build.gradle.kts | 28 +++++++ buildSrc/build.gradle.kts | 5 -- .../cc-tweaked.java-convention.gradle.kts | 18 +++-- .../cc/tweaked/gradle/CCTweakedExtension.kt | 9 ++- .../cc/tweaked/gradle/CCTweakedPlugin.kt | 17 ++-- .../kotlin/cc/tweaked/gradle/Extensions.kt | 10 +++ .../cc/tweaked/gradle/MavenDependencySpec.kt | 62 +++++++++++++++ .../main/kotlin/cc/tweaked/gradle/XmlUtil.kt | 12 +++ gradle.properties | 3 +- projects/ARCHITECTURE.md | 2 +- .../client/sound/SpeakerSound.java | 8 +- .../annotations/FabricOverride.java | 17 ++++ .../computercraft/lua/rom/help/changelog.md | 4 + .../computercraft/lua/rom/help/whatsnew.md | 6 +- projects/fabric-api/build.gradle.kts | 2 +- projects/fabric/build.gradle.kts | 31 +++++++- projects/forge/build.gradle.kts | 79 +++++++------------ 17 files changed, 227 insertions(+), 86 deletions(-) create mode 100644 buildSrc/src/main/kotlin/cc/tweaked/gradle/MavenDependencySpec.kt create mode 100644 buildSrc/src/main/kotlin/cc/tweaked/gradle/XmlUtil.kt create mode 100644 projects/common/src/main/java/dan200/computercraft/annotations/FabricOverride.java diff --git a/build.gradle.kts b/build.gradle.kts index b4a123fd6..4ef4c478f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,10 +2,38 @@ import org.jetbrains.gradle.ext.compiler import org.jetbrains.gradle.ext.settings plugins { + publishing alias(libs.plugins.taskTree) + alias(libs.plugins.githubRelease) id("org.jetbrains.gradle.plugin.idea-ext") + id("cc-tweaked") } +val isUnstable = project.properties["isUnstable"] == "true" +val modVersion: String by extra +val mcVersion: String by extra + +githubRelease { + token(findProperty("githubApiKey") as String? ?: "") + owner.set("cc-tweaked") + repo.set("CC-Tweaked") + targetCommitish.set(cct.gitBranch) + + tagName.set("v$mcVersion-$modVersion") + releaseName.set("[$mcVersion] $modVersion") + body.set( + provider { + "## " + project(":core").file("src/main/resources/data/computercraft/lua/rom/help/whatsnew.md") + .readLines() + .takeWhile { it != "Type \"help changelog\" to see the full version history." } + .joinToString("\n").trim() + }, + ) + prerelease.set(isUnstable) +} + +tasks.publish { dependsOn(tasks.githubRelease) } + idea.project.settings.compiler.javac { // We want ErrorProne to be present when compiling via IntelliJ, as it offers some helpful warnings // and errors. Loop through our source sets and find the appropriate flags. diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 517dcf18c..52e25e29d 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -3,11 +3,6 @@ plugins { `kotlin-dsl` } -repositories { - mavenCentral() - gradlePluginPortal() -} - // Duplicated in settings.gradle.kts repositories { mavenCentral() diff --git a/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts b/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts index 1d29372c8..38bfdb8ad 100644 --- a/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts +++ b/buildSrc/src/main/kotlin/cc-tweaked.java-convention.gradle.kts @@ -1,3 +1,4 @@ +import cc.tweaked.gradle.CCTweakedExtension import cc.tweaked.gradle.CCTweakedPlugin import cc.tweaked.gradle.LicenseHeader import com.diffplug.gradle.spotless.FormatExtension @@ -21,10 +22,7 @@ val mcVersion: String by extra group = "cc.tweaked" version = modVersion -base.archivesName.convention( - // TODO: Remove this (and the one below) once we've no longer got a root project! - if (project.path == rootProject.path) "cc-tweaked-$mcVersion" else "cc-tweaked-$mcVersion-${project.name}", -) +base.archivesName.convention("cc-tweaked-$mcVersion-${project.name}") java { toolchain { @@ -104,6 +102,8 @@ tasks.withType(JavaCompile::class.java).configureEach { tasks.withType(AbstractArchiveTask::class.java).configureEach { isPreserveFileTimestamps = false isReproducibleFileOrder = true + dirMode = Integer.valueOf("755", 8) + fileMode = Integer.valueOf("664", 8) } tasks.jar { @@ -112,7 +112,7 @@ tasks.jar { "Specification-Title" to "computercraft", "Specification-Vendor" to "SquidDev", "Specification-Version" to "1", - "Implementation-Title" to (if (project.path == rootProject.path) "cctweaked" else "cctweaked-${project.name}"), + "Implementation-Title" to "cctweaked-${project.name}", "Implementation-Version" to modVersion, "Implementation-Vendor" to "SquidDev", ) @@ -141,6 +141,14 @@ tasks.withType(JacocoReport::class.java).configureEach { reports.html.required.set(true) } +project.plugins.withType(CCTweakedPlugin::class.java) { + // Set up jacoco to read from /all/ our source directories. + val cct = project.extensions.getByType() + project.tasks.named("jacocoTestReport", JacocoReport::class.java) { + for (ref in cct.sourceSets.get()) sourceDirectories.from(ref.allSource.sourceDirectories) + } +} + spotless { encoding = StandardCharsets.UTF_8 lineEndings = LineEnding.UNIX diff --git a/buildSrc/src/main/kotlin/cc/tweaked/gradle/CCTweakedExtension.kt b/buildSrc/src/main/kotlin/cc/tweaked/gradle/CCTweakedExtension.kt index b1a467eb5..0e9f1b124 100644 --- a/buildSrc/src/main/kotlin/cc/tweaked/gradle/CCTweakedExtension.kt +++ b/buildSrc/src/main/kotlin/cc/tweaked/gradle/CCTweakedExtension.kt @@ -87,16 +87,17 @@ abstract class CCTweakedExtension( init { sourceDirectories.finalizeValueOnRead() + project.afterEvaluate { sourceDirectories.disallowChanges() } } /** - * Mark this project as consuming another project. Its [sourceDirectories] are added, ensuring tasks are set up - * correctly. + * Mark this project as consuming another project. Its [sourceDirectories] are added, allowing easier configuration + * of run configurations and other tasks which consume sources/classes. */ fun externalSources(project: Project) { val otherCct = project.extensions.getByType(CCTweakedExtension::class.java) - for (sourceSet in otherCct.sourceSets.get()) { - sourceDirectories.add(SourceSetReference.external(sourceSet)) + for (sourceSet in otherCct.sourceDirectories.get()) { + sourceDirectories.add(SourceSetReference(sourceSet.sourceSet, classes = sourceSet.classes, external = true)) } } diff --git a/buildSrc/src/main/kotlin/cc/tweaked/gradle/CCTweakedPlugin.kt b/buildSrc/src/main/kotlin/cc/tweaked/gradle/CCTweakedPlugin.kt index 8286c12d0..919d87b38 100644 --- a/buildSrc/src/main/kotlin/cc/tweaked/gradle/CCTweakedPlugin.kt +++ b/buildSrc/src/main/kotlin/cc/tweaked/gradle/CCTweakedPlugin.kt @@ -2,27 +2,20 @@ package cc.tweaked.gradle import org.gradle.api.Plugin import org.gradle.api.Project -import org.gradle.api.tasks.SourceSetContainer +import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.plugins.JavaPluginExtension import org.gradle.jvm.toolchain.JavaLanguageVersion -import org.gradle.testing.jacoco.tasks.JacocoReport /** * Configures projects to match a shared configuration. */ class CCTweakedPlugin : Plugin { override fun apply(project: Project) { - val sourceSets = project.extensions.getByType(SourceSetContainer::class.java) - val cct = project.extensions.create("cct", CCTweakedExtension::class.java) - cct.sourceDirectories.add(SourceSetReference.internal(sourceSets.getByName("main"))) - project.afterEvaluate { - cct.sourceDirectories.disallowChanges() - } - - // Set up jacoco to read from /all/ our source directories. - project.tasks.named("jacocoTestReport", JacocoReport::class.java) { - for (ref in cct.sourceSets.get()) sourceDirectories.from(ref.allSource.sourceDirectories) + project.plugins.withType(JavaPlugin::class.java) { + val sourceSets = project.extensions.getByType(JavaPluginExtension::class.java).sourceSets + cct.sourceDirectories.add(SourceSetReference.internal(sourceSets.getByName("main"))) } } diff --git a/buildSrc/src/main/kotlin/cc/tweaked/gradle/Extensions.kt b/buildSrc/src/main/kotlin/cc/tweaked/gradle/Extensions.kt index fc0a4b5f2..612715506 100644 --- a/buildSrc/src/main/kotlin/cc/tweaked/gradle/Extensions.kt +++ b/buildSrc/src/main/kotlin/cc/tweaked/gradle/Extensions.kt @@ -1,8 +1,15 @@ package cc.tweaked.gradle +import org.gradle.api.artifacts.ResolvedDependency import org.gradle.api.artifacts.dsl.DependencyHandler +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.specs.Spec import org.gradle.api.tasks.JavaExec +import org.gradle.process.JavaExecSpec +/** + * Add an annotation processor to all source sets. + */ fun DependencyHandler.annotationProcessorEverywhere(dep: Any) { add("compileOnly", dep) add("annotationProcessor", dep) @@ -14,6 +21,9 @@ fun DependencyHandler.annotationProcessorEverywhere(dep: Any) { add("testAnnotationProcessor", dep) } +/** + * A version of [JavaExecSpec.copyTo] which copies *all* properties. + */ fun JavaExec.copyToFull(spec: JavaExec) { copyTo(spec) spec.classpath = classpath diff --git a/buildSrc/src/main/kotlin/cc/tweaked/gradle/MavenDependencySpec.kt b/buildSrc/src/main/kotlin/cc/tweaked/gradle/MavenDependencySpec.kt new file mode 100644 index 000000000..d7755ed38 --- /dev/null +++ b/buildSrc/src/main/kotlin/cc/tweaked/gradle/MavenDependencySpec.kt @@ -0,0 +1,62 @@ +package cc.tweaked.gradle + +import org.gradle.api.artifacts.Dependency +import org.gradle.api.artifacts.MinimalExternalModuleDependency +import org.gradle.api.publish.maven.MavenPublication +import org.gradle.api.specs.Spec + +/** + * A dependency in a POM file. + */ +data class MavenDependency(val groupId: String?, val artifactId: String?, val version: String?, val scope: String?) + +/** + * A spec specifying which dependencies to include/exclude. + */ +class MavenDependencySpec { + private val excludeSpecs = mutableListOf>() + + fun exclude(spec: Spec) { + excludeSpecs.add(spec) + } + + fun exclude(dep: Dependency) { + exclude { + (dep.group.isNullOrEmpty() || dep.group == it.groupId) && + (dep.name.isNullOrEmpty() || dep.name == it.artifactId) && + (dep.version.isNullOrEmpty() || dep.version == it.version) + } + } + + fun exclude(dep: MinimalExternalModuleDependency) { + exclude { + dep.module.group == it.groupId && dep.module.name == it.artifactId + } + } + + fun isIncluded(dep: MavenDependency) = !excludeSpecs.any { it.isSatisfiedBy(dep) } +} + +/** + * Configure dependencies present in this publication's POM file. + * + * While this approach is very ugly, it's the easiest way to handle it! + */ +fun MavenPublication.mavenDependencies(action: MavenDependencySpec.() -> Unit) { + val spec = MavenDependencySpec() + action(spec) + + pom.withXml { + val dependencies = XmlUtil.findChild(asNode(), "dependencies") ?: return@withXml + dependencies.children().map { it as groovy.util.Node }.forEach { + val dep = MavenDependency( + groupId = XmlUtil.findChild(it, "groupId")?.text(), + artifactId = XmlUtil.findChild(it, "artifactId")?.text(), + version = XmlUtil.findChild(it, "version")?.text(), + scope = XmlUtil.findChild(it, "scope")?.text(), + ) + + if (!spec.isIncluded(dep)) it.parent().remove(it) + } + } +} diff --git a/buildSrc/src/main/kotlin/cc/tweaked/gradle/XmlUtil.kt b/buildSrc/src/main/kotlin/cc/tweaked/gradle/XmlUtil.kt new file mode 100644 index 000000000..1e610c798 --- /dev/null +++ b/buildSrc/src/main/kotlin/cc/tweaked/gradle/XmlUtil.kt @@ -0,0 +1,12 @@ +package cc.tweaked.gradle + +import groovy.util.Node +import groovy.util.NodeList + +object XmlUtil { + fun findChild(node: Node, name: String): Node? = when (val child = node.get(name)) { + is Node -> child + is NodeList -> child.singleOrNull() as Node? + else -> null + } +} diff --git a/gradle.properties b/gradle.properties index 693e3cde3..8f948b486 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,7 +5,8 @@ kotlin.stdlib.default.dependency=false kotlin.jvm.target.validation.mode=error # Mod properties -modVersion=1.101.1 +isUnstable=true +modVersion=1.102.0-SNAPSHOT # Minecraft properties: We want to configure this here so we can read it in settings.gradle mcVersion=1.19.2 diff --git a/projects/ARCHITECTURE.md b/projects/ARCHITECTURE.md index e52699629..4adface01 100644 --- a/projects/ARCHITECTURE.md +++ b/projects/ARCHITECTURE.md @@ -59,7 +59,7 @@ mentioning: - `web`: This contains the additional tooling for building [the documentation website][tweaked.cc], such as support for rendering recipes - - `build-logic` (in the base directory, not in `projects/`): This contains any build logic shared between modules. For + - `buildSrc` (in the base directory, not in `projects/`): This contains any build logic shared between modules. For instance, `cc-tweaked.java-convention.gradle.kts` sets up the defaults for Java that we use across the whole project. > **Note** diff --git a/projects/common/src/client/java/dan200/computercraft/client/sound/SpeakerSound.java b/projects/common/src/client/java/dan200/computercraft/client/sound/SpeakerSound.java index e0be0aac2..9f9fed1dc 100644 --- a/projects/common/src/client/java/dan200/computercraft/client/sound/SpeakerSound.java +++ b/projects/common/src/client/java/dan200/computercraft/client/sound/SpeakerSound.java @@ -5,6 +5,7 @@ */ package dan200.computercraft.client.sound; +import dan200.computercraft.annotations.FabricOverride; import dan200.computercraft.annotations.ForgeOverride; import dan200.computercraft.shared.peripheral.speaker.SpeakerPosition; import net.minecraft.client.resources.sounds.AbstractSoundInstance; @@ -64,7 +65,12 @@ public class SpeakerSound extends AbstractSoundInstance implements TickableSound @ForgeOverride public CompletableFuture getStream(SoundBufferLibrary soundBuffers, Sound sound, boolean looping) { - return stream != null ? CompletableFuture.completedFuture(stream) : soundBuffers.getStream(sound.getPath(), looping); + return getAudioStream(soundBuffers, sound.getPath(), looping); + } + + @FabricOverride + public CompletableFuture getAudioStream(SoundBufferLibrary soundBuffers, ResourceLocation sound, boolean looping) { + return stream != null ? CompletableFuture.completedFuture(stream) : soundBuffers.getStream(sound, looping); } public @Nullable AudioStream getStream() { diff --git a/projects/common/src/main/java/dan200/computercraft/annotations/FabricOverride.java b/projects/common/src/main/java/dan200/computercraft/annotations/FabricOverride.java new file mode 100644 index 000000000..f42c1b989 --- /dev/null +++ b/projects/common/src/main/java/dan200/computercraft/annotations/FabricOverride.java @@ -0,0 +1,17 @@ +/* + * This file is part of ComputerCraft - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2022. Do not distribute without permission. + * Send enquiries to dratcliffe@gmail.com + */ +package dan200.computercraft.annotations; + +import java.lang.annotation.*; + +/** + * Equivalent to {@link Override}, but for Fabric-specific methods. + */ +@Documented +@Retention(RetentionPolicy.SOURCE) +@Target(ElementType.METHOD) +public @interface FabricOverride { +} diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/help/changelog.md b/projects/core/src/main/resources/data/computercraft/lua/rom/help/changelog.md index 1ca769b66..86f03d538 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/help/changelog.md +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/help/changelog.md @@ -1,3 +1,7 @@ +# New features in CC: Tweaked 1.102.0-SNAPSHOT + +No user-facing changes. + # New features in CC: Tweaked 1.101.1 Several bug fixes: diff --git a/projects/core/src/main/resources/data/computercraft/lua/rom/help/whatsnew.md b/projects/core/src/main/resources/data/computercraft/lua/rom/help/whatsnew.md index 9342983bd..bdd71cc53 100644 --- a/projects/core/src/main/resources/data/computercraft/lua/rom/help/whatsnew.md +++ b/projects/core/src/main/resources/data/computercraft/lua/rom/help/whatsnew.md @@ -1,7 +1,5 @@ -New features in CC: Tweaked 1.101.1 +New features in CC: Tweaked 1.102.0-SNAPSHOT -Several bug fixes: -* Improve validation of rednet messages (Ale32bit) -* Fix `turtle.refuel()` always failing. +No user-facing changes. Type "help changelog" to see the full version history. diff --git a/projects/fabric-api/build.gradle.kts b/projects/fabric-api/build.gradle.kts index 1067f8e8e..f914254a4 100644 --- a/projects/fabric-api/build.gradle.kts +++ b/projects/fabric-api/build.gradle.kts @@ -1,6 +1,6 @@ plugins { - id("cc-tweaked.publishing") id("cc-tweaked.fabric") + id("cc-tweaked.publishing") } val mcVersion: String by extra diff --git a/projects/fabric/build.gradle.kts b/projects/fabric/build.gradle.kts index 1c052b724..c90ac7132 100644 --- a/projects/fabric/build.gradle.kts +++ b/projects/fabric/build.gradle.kts @@ -1,11 +1,13 @@ import cc.tweaked.gradle.annotationProcessorEverywhere import cc.tweaked.gradle.clientClasses import cc.tweaked.gradle.commonClasses +import cc.tweaked.gradle.mavenDependencies import net.fabricmc.loom.configuration.ide.RunConfigSettings plugins { id("cc-tweaked.fabric") id("cc-tweaked.gametest") + id("cc-tweaked.publishing") } val modVersion: String by extra @@ -35,10 +37,15 @@ dependencies { include(libs.nightConfig.toml) // Pull in our other projects. See comments in MinecraftConfigurations on this nastiness. + api(commonClasses(project(":fabric-api"))) + clientApi(clientClasses(project(":fabric-api"))) implementation(project(":core")) + // These are transitive deps of :core, so we don't need these deps. However, we want them to appear as runtime deps + // in our POM, and this is the easiest way. + runtimeOnly(libs.cobalt) + runtimeOnly(libs.netty.http) + compileOnly(project(":forge-stubs")) - implementation(commonClasses(project(":fabric-api"))) - clientImplementation(clientClasses(project(":fabric-api"))) annotationProcessorEverywhere(libs.autoService) @@ -137,7 +144,13 @@ tasks.processResources { } tasks.jar { - from(allProjects.map { zipTree(it.tasks.jar.get().archiveFile) }) + for (source in cct.sourceDirectories.get()) { + if (source.classes && source.external) from(source.sourceSet.output) + } +} + +tasks.sourcesJar { + for (source in cct.sourceDirectories.get()) from(source.sourceSet.allSource) } val validateMixinNames by tasks.registering(net.fabricmc.loom.task.ValidateMixinNameTask::class) { @@ -153,3 +166,15 @@ val runGametest = tasks.named("runGametest") cct.jacoco(runGametest) tasks.check { dependsOn(validateMixinNames, runGametest) } + +tasks.withType(GenerateModuleMetadata::class).configureEach { isEnabled = false } +publishing { + publications { + named("maven", MavenPublication::class) { + mavenDependencies { + exclude(dependencies.create("cc.tweaked:")) + exclude(libs.jei.fabric.get()) + } + } + } +} diff --git a/projects/forge/build.gradle.kts b/projects/forge/build.gradle.kts index 83ba4509e..493d012fd 100644 --- a/projects/forge/build.gradle.kts +++ b/projects/forge/build.gradle.kts @@ -1,6 +1,4 @@ import cc.tweaked.gradle.* -import groovy.util.Node -import groovy.util.NodeList import net.darkhax.curseforgegradle.TaskPublishCurseForge import net.minecraftforge.gradle.common.util.RunConfig @@ -12,7 +10,6 @@ plugins { alias(libs.plugins.shadow) // Publishing alias(libs.plugins.curseForgeGradle) - alias(libs.plugins.githubRelease) alias(libs.plugins.minotaur) id("cc-tweaked.illuaminate") @@ -20,7 +17,7 @@ plugins { id("cc-tweaked") } -val isStable = true +val isUnstable = project.properties["isUnstable"] == "true" val modVersion: String by extra val mcVersion: String by extra @@ -41,10 +38,6 @@ minecraft { // configureEach would be better, but we need to eagerly configure configs or otherwise the run task doesn't // get set up properly. all { - lazyToken("minecraft_classpath") { - configurations["shade"].copyRecursive().resolve().joinToString(File.pathSeparator) { it.absolutePath } - } - property("forge.logging.markers", "REGISTRIES") property("forge.logging.console.level", "debug") @@ -78,7 +71,7 @@ minecraft { } fun RunConfig.configureForGameTest() { - val old = lazyTokens.get("minecraft_classpath") + val old = lazyTokens["minecraft_classpath"] lazyToken("minecraft_classpath") { // We do some terrible hacks here to basically find all things not already on the runtime classpath // and add them. /Except/ for our source sets, as those need to load inside the Minecraft classpath. @@ -89,7 +82,9 @@ minecraft { .filter { it.isFile && !it.name.endsWith("-test-fixtures.jar") } .map { it.absolutePath } .joinToString(File.pathSeparator) - if (old == null) new else old.get() + File.pathSeparator + new + + val oldVal = old?.get() + if (oldVal.isNullOrEmpty()) new else oldVal + File.pathSeparator + new } property("cctest.sources", project(":common").file("src/testMod/resources/data/cctest").absolutePath) @@ -131,8 +126,6 @@ reobf { } configurations { - val shade by registering { isTransitive = false } - implementation { extendsFrom(shade.get()) } register("cctJavadoc") } @@ -145,11 +138,14 @@ dependencies { libs.bundles.externalMods.forge.compile.get().map { compileOnly(fg.deobf(it)) } libs.bundles.externalMods.forge.runtime.get().map { runtimeOnly(fg.deobf(it)) } + // Depend on our other projects. By using the api configuration, shadow jar will correctly + // preserve all files from forge-api/core-api. + api(commonClasses(project(":forge-api"))) + api(clientClasses(project(":forge-api"))) implementation(project(":core")) - implementation(commonClasses(project(":forge-api"))) - implementation(clientClasses(project(":forge-api"))) - "shade"(libs.cobalt) - "shade"(libs.netty.http) + + minecraftLibrary(libs.cobalt) + minecraftLibrary(libs.netty.http) { isTransitive = false } testFixturesApi(libs.bundles.test) testFixturesApi(libs.bundles.kotlin) @@ -206,19 +202,27 @@ tasks.jar { finalizedBy("reobfJar") archiveClassifier.set("slim") - from(allProjects.map { zipTree(it.tasks.jar.get().archiveFile) }) + for (source in cct.sourceDirectories.get()) { + if (source.classes && source.external) from(source.sourceSet.output) + } +} + +tasks.sourcesJar { + for (source in cct.sourceDirectories.get()) from(source.sourceSet.allSource) } tasks.shadowJar { finalizedBy("reobfShadowJar") archiveClassifier.set("") - from(allProjects.map { zipTree(it.tasks.jar.get().archiveFile) }) - - configurations = listOf(project.configurations["shade"]) + dependencies { + include(dependency("cc.tweaked:")) + include(dependency(libs.cobalt.get())) + include(dependency(libs.netty.http.get())) + } relocate("org.squiddev.cobalt", "cc.tweaked.internal.cobalt") relocate("io.netty.handler", "cc.tweaked.internal.netty") - // TODO: minimize(): Would be good to support once our build scripts are stabilised. + minimize() } tasks.assemble { dependsOn("shadowJar") } @@ -276,7 +280,7 @@ val publishCurseForge by tasks.registering(TaskPublishCurseForge::class) { mainFile.changelog = "Release notes can be found on the [GitHub repository](https://github.com/cc-tweaked/CC-Tweaked/releases/tag/v$mcVersion-$modVersion)." mainFile.changelogType = "markdown" - mainFile.releaseType = if (isStable) "release" else "alpha" + mainFile.releaseType = if (isUnstable) "alpha" else "release" mainFile.gameVersions.add(mcVersion) } @@ -287,7 +291,7 @@ modrinth { projectId.set("gu7yAYhd") versionNumber.set("$mcVersion-$modVersion") versionName.set(modVersion) - versionType.set(if (isStable) "release" else "alpha") + versionType.set(if (isUnstable) "alpha" else "release") uploadFile.set(tasks.shadowJar as Any) gameVersions.add(mcVersion) changelog.set("Release notes can be found on the [GitHub repository](https://github.com/cc-tweaked/CC-Tweaked/releases/tag/v$mcVersion-$modVersion).") @@ -297,27 +301,6 @@ modrinth { tasks.publish { dependsOn(tasks.modrinth) } -githubRelease { - token(findProperty("githubApiKey") as String? ?: "") - owner.set("cc-tweaked") - repo.set("CC-Tweaked") - targetCommitish.set(cct.gitBranch) - - tagName.set("v$mcVersion-$modVersion") - releaseName.set("[$mcVersion] $modVersion") - body.set( - provider { - "## " + file("src/main/resources/data/computercraft/lua/rom/help/whatsnew.md") - .readLines() - .takeWhile { it != "Type \"help changelog\" to see the full version history." } - .joinToString("\n").trim() - }, - ) - prerelease.set(!isStable) -} - -tasks.publish { dependsOn(tasks.githubRelease) } - // Don't publish the slim jar for (cfg in listOf(configurations.apiElements, configurations.runtimeElements)) { cfg.configure { artifacts.removeIf { it.classifier == "slim" } } @@ -327,11 +310,9 @@ publishing { publications { named("maven", MavenPublication::class) { fg.component(this) - // Remove all dependencies: they're shaded anyway! This is very ugly, but not found a better way :(. - pom.withXml { - for (node in asNode().get("dependencies") as NodeList) { - asNode().remove(node as Node) - } + mavenDependencies { + exclude(dependencies.create("cc.tweaked:")) + exclude(libs.jei.forge.get()) } } }