From 89b1791b03613054564a7f94576caccd63586df4 Mon Sep 17 00:00:00 2001 From: shartte Date: Tue, 11 Jun 2024 20:45:45 +0200 Subject: [PATCH] Publishing extended Gradle Module Metadata for Tooling (#959) Co-authored-by: Technici4n <13494793+Technici4n@users.noreply.github.com> --- build.gradle | 5 - projects/neoforge/build.gradle | 222 +++++++++++++++++++++++++++++---- 2 files changed, 196 insertions(+), 31 deletions(-) diff --git a/build.gradle b/build.gradle index 9244f6a6a5..183cf8203f 100644 --- a/build.gradle +++ b/build.gradle @@ -27,11 +27,6 @@ if (isPreReleaseVersion) { } } - changelog { - from '20.6' - disableAutomaticPublicationRegistration() - } - project.version = gradleutils.version.toString() } diff --git a/projects/neoforge/build.gradle b/projects/neoforge/build.gradle index 0100bf10cf..453ca11005 100644 --- a/projects/neoforge/build.gradle +++ b/projects/neoforge/build.gradle @@ -3,7 +3,14 @@ plugins { id 'maven-publish' } -rootProject.gradleutils.setupSigning(project: project, signAllPublications: true) +apply plugin: 'net.neoforged.gradleutils' + +gradleutils.setupSigning(project: project, signAllPublications: true) + +changelog { + from '20.6' + disableAutomaticPublicationRegistration() +} dynamicProject { runtime("${project.minecraft_version}-${project.neoform_version}", @@ -207,8 +214,6 @@ tasks.withType(Javadoc.class).configureEach { options.addStringOption('Xdoclint:all,-missing', '-public') } -tasks.withType(GenerateModuleMetadata).configureEach { enabled = false } - configurations { forValidation { canBeConsumed = true @@ -230,6 +235,193 @@ artifacts { } } +AdhocComponentWithVariants javaComponent = (AdhocComponentWithVariants) project.components.findByName("java") +// Ensure the two default variants are not published, since they +// contain Minecraft classes +javaComponent.withVariantsFromConfiguration(configurations.apiElements) { + it.skip() +} +javaComponent.withVariantsFromConfiguration(configurations.runtimeElements) { + it.skip() +} + +configurations { + modDevBundle { + canBeResolved = false + canBeConsumed = true + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, "data")) + attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) + } + outgoing { + capability("net.neoforged:neoforge-moddev-bundle:${project.version}") + } + javaComponent.addVariantsFromConfiguration(it) {} // Publish it + } + modDevConfig { + canBeResolved = false + canBeConsumed = true + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, "data")) + attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) + } + outgoing { + capability("net.neoforged:neoforge-moddev-config:${project.version}") + } + javaComponent.addVariantsFromConfiguration(it) {} // Publish it + } + installerJar { + canBeResolved = false + canBeConsumed = true + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) + attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EMBEDDED)) + // The installer targets JDK 8 + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8) + } + outgoing { + capability("net.neoforged:neoforge-installer:${project.version}") + } + // Publish it + javaComponent.addVariantsFromConfiguration(it) {} + } + universalJar { + canBeResolved = false + canBeConsumed = true + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) + attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) + attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, JavaVersion.current().majorVersion.toInteger()) + attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objects.named(LibraryElements, LibraryElements.JAR)) + } + // Publish it + javaComponent.addVariantsFromConfiguration(it) {} + } + changelog { + canBeResolved = false + canBeConsumed = true + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType, "changelog")) + } + // Publish it, but only for release versions + if (!rootProject.isPreReleaseVersion) { + javaComponent.addVariantsFromConfiguration(it) {} + } + } + modDevApiElements { + canBeResolved = false + canBeConsumed = true + afterEvaluate { + extendsFrom userdevCompileOnly, installerLibraries, moduleOnly + } + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) + attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_API)) + } + outgoing { + capability("net.neoforged:neoforge-dependencies:${project.version}") + } + javaComponent.addVariantsFromConfiguration(it) {} + } + modDevRuntimeElements { + canBeResolved = false + canBeConsumed = true + afterEvaluate { + extendsFrom installerLibraries, moduleOnly + } + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) + attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) + } + outgoing { + capability("net.neoforged:neoforge-dependencies:${project.version}") + } + javaComponent.addVariantsFromConfiguration(it) {} + } + modDevModulePath { + canBeResolved = false + canBeConsumed = true + afterEvaluate { + extendsFrom moduleOnly + } + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) + attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) + } + outgoing { + capability("net.neoforged:neoforge-moddev-module-path:${project.version}") + } + javaComponent.addVariantsFromConfiguration(it) {} + } + modDevTestFixtures { + canBeResolved = false + canBeConsumed = true + attributes { + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category, Category.LIBRARY)) + attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling, Bundling.EXTERNAL)) + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage, Usage.JAVA_RUNTIME)) + } + outgoing { + capability("net.neoforged:neoforge-moddev-test-fixtures:${project.version}") + } + javaComponent.addVariantsFromConfiguration(it) {} + } +} + +dependencies { + modDevBundle("net.neoforged:neoform:${project.minecraft_version}-${project.neoform_version}") { + capabilities { + requireCapability 'net.neoforged:neoform' + } + endorseStrictVersions() + } + modDevApiElements("net.neoforged:neoform:${project.minecraft_version}-${project.neoform_version}") { + capabilities { + requireCapability 'net.neoforged:neoform-dependencies' + } + endorseStrictVersions() + } + modDevRuntimeElements("net.neoforged:neoform:${project.minecraft_version}-${project.neoform_version}") { + capabilities { + requireCapability 'net.neoforged:neoform-dependencies' + } + endorseStrictVersions() + } + modDevTestFixtures("net.neoforged.fancymodloader:junit-fml:${project.fancy_mod_loader_version}") { + endorseStrictVersions() + } +} + +afterEvaluate { + artifacts { + modDevBundle(userdevJar) { + setClassifier("userdev") // Legacy + } + modDevConfig(createUserdevJson.output) { + builtBy(createUserdevJson) + setClassifier("moddev-config") + } + universalJar(signUniversalJar.output) { + builtBy(signUniversalJar) + setClassifier("universal") + } + installerJar(signInstallerJar.output) { + builtBy(signInstallerJar) + setClassifier("installer") + } + changelog(createChangelog.outputFile) { + builtBy(createChangelog) + setClassifier("changelog") + setExtension("txt") + } + } +} + publishing { publications.create('NeoForge', MavenPublication) { groupId = project.group @@ -238,28 +430,6 @@ publishing { from components.java - artifacts = [] - - afterEvaluate { - artifact (signUniversalJar.output) { - classifier 'universal' - } - artifact (signInstallerJar.output) { - classifier 'installer' - } - artifact (userdevJar) { - classifier 'userdev' - } - artifact (sourcesJar) { - classifier 'sources' - } - } - - if (!rootProject.isPreReleaseVersion) { - // Only publish a changelog for releases - changelog.publish(it) - } - versionMapping { usage('java-api') { fromResolutionOf('runtimeClasspath') @@ -295,6 +465,6 @@ publishing { } } repositories { - maven rootProject.gradleutils.getPublishingMaven() + maven gradleutils.getPublishingMaven() } }