[build, minecraft] Publishing as Minecraft Fabric mods
This commit is contained in:
@@ -4,4 +4,8 @@ plugins {
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(project(":helpers"))
|
||||
}
|
||||
|
||||
15
buildSrc/helpers/build.gradle.kts
Normal file
15
buildSrc/helpers/build.gradle.kts
Normal file
@@ -0,0 +1,15 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
`java-gradle-plugin`
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
gradlePlugin {
|
||||
plugins.register("minecraftModComponent") {
|
||||
id = "de.siphalor.tweed5.minecraft.mod.component"
|
||||
implementationClass = "de.siphalor.tweed5.gradle.plugin.minecraft.mod.MinecraftModComponentPlugin"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package de.siphalor.tweed5.gradle.plugin.minecraft.mod
|
||||
|
||||
import org.gradle.api.JavaVersion
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.attributes.Bundling
|
||||
import org.gradle.api.attributes.Category
|
||||
import org.gradle.api.attributes.DocsType
|
||||
import org.gradle.api.attributes.LibraryElements
|
||||
import org.gradle.api.attributes.Usage
|
||||
import org.gradle.api.attributes.java.TargetJvmVersion
|
||||
import org.gradle.api.component.SoftwareComponentFactory
|
||||
import org.gradle.api.model.ObjectFactory
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.kotlin.dsl.named
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class MinecraftModComponentPlugin : Plugin<Project> {
|
||||
@get:Inject
|
||||
abstract val softwareComponentFactory: SoftwareComponentFactory
|
||||
|
||||
@get:Inject
|
||||
abstract val objectFactory: ObjectFactory
|
||||
|
||||
override fun apply(project: Project) {
|
||||
val modComponent = softwareComponentFactory.adhoc("minecraftMod")
|
||||
project.components.add(modComponent)
|
||||
|
||||
val targetJvmVersion = project.tasks.named<JavaCompile>("compileJava")
|
||||
.map { JavaVersion.toVersion(it.targetCompatibility).majorVersion }
|
||||
|
||||
val modElementsConfiguration = project.configurations.consumable("minecraftModElements") {
|
||||
attributes {
|
||||
attribute(MinecraftModded.MINECRAFT_MODDED_ATTRIBUTE, objectFactory.named(MinecraftModded.MODDED))
|
||||
attribute(Category.CATEGORY_ATTRIBUTE, objectFactory.named(Category.LIBRARY))
|
||||
attribute(LibraryElements.LIBRARY_ELEMENTS_ATTRIBUTE, objectFactory.named(LibraryElements.JAR))
|
||||
attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling.SHADOWED))
|
||||
attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.JAVA_RUNTIME))
|
||||
|
||||
project.afterEvaluate {
|
||||
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, targetJvmVersion.get().toInt())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val apiConfiguration = project.configurations.named("api")
|
||||
val modSourcesElementsConfiguration = project.configurations.consumable("minecraftModSourcesElements") {
|
||||
extendsFrom(apiConfiguration.get())
|
||||
attributes {
|
||||
attribute(MinecraftModded.MINECRAFT_MODDED_ATTRIBUTE, objectFactory.named(MinecraftModded.MODDED))
|
||||
attribute(Category.CATEGORY_ATTRIBUTE, objectFactory.named(Category.DOCUMENTATION))
|
||||
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objectFactory.named(DocsType.SOURCES))
|
||||
attribute(Bundling.BUNDLING_ATTRIBUTE, objectFactory.named(Bundling.EXTERNAL))
|
||||
}
|
||||
}
|
||||
|
||||
modComponent.addVariantsFromConfiguration(modElementsConfiguration.get()) {
|
||||
mapToMavenScope("runtime")
|
||||
}
|
||||
modComponent.addVariantsFromConfiguration(modSourcesElementsConfiguration.get()) {
|
||||
mapToOptional()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package de.siphalor.tweed5.gradle.plugin.minecraft.mod
|
||||
|
||||
import org.gradle.api.Named
|
||||
import org.gradle.api.attributes.Attribute
|
||||
|
||||
interface MinecraftModded : Named {
|
||||
companion object {
|
||||
val MINECRAFT_MODDED_ATTRIBUTE = Attribute.of("de.siphalor.tweed5.minecraft.modded", MinecraftModded::class.java)
|
||||
const val PLAIN = "plain"
|
||||
const val MODDED = "modded"
|
||||
}
|
||||
}
|
||||
@@ -2,4 +2,6 @@ plugins {
|
||||
id("dev.panuszewski.typesafe-conventions") version "0.7.3"
|
||||
}
|
||||
|
||||
include("helpers")
|
||||
|
||||
rootProject.name = "tweed5-conventions"
|
||||
|
||||
@@ -73,7 +73,7 @@ tasks.test {
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("maven") {
|
||||
create<MavenPublication>("lib") {
|
||||
groupId = project.group.toString()
|
||||
artifactId = project.name
|
||||
version = project.version.toString()
|
||||
|
||||
@@ -8,6 +8,8 @@ plugins {
|
||||
|
||||
val expandedSourcesElements = configurations.consumable("expandedSourcesElements") {
|
||||
attributes {
|
||||
attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION))
|
||||
attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named(DocsType.SOURCES))
|
||||
attribute(Bundling.BUNDLING_ATTRIBUTE, objects.named(Bundling.EXTERNAL))
|
||||
}
|
||||
}
|
||||
@@ -15,6 +17,8 @@ val expandedSourcesElements = configurations.consumable("expandedSourcesElements
|
||||
val delombok = tasks.getByName<Delombok>("delombok")
|
||||
|
||||
val sourcesJar by tasks.registering(Jar::class) {
|
||||
group = LifecycleBasePlugin.BUILD_GROUP
|
||||
|
||||
dependsOn(delombok)
|
||||
from(delombok.target)
|
||||
archiveClassifier.set("sources")
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
plugins {
|
||||
`maven-publish`
|
||||
alias(libs.plugins.shadow)
|
||||
id("de.siphalor.tweed5.expanded-sources-jar")
|
||||
id("de.siphalor.tweed5.minecraft.mod.component")
|
||||
}
|
||||
|
||||
tasks.shadowJar {
|
||||
relocate("org.apache.commons", "de.siphalor.tweed5.shadowed.org.apache.commons")
|
||||
}
|
||||
|
||||
val minecraftModJar = tasks.register<Jar>("minecraftModJar") {
|
||||
group = LifecycleBasePlugin.BUILD_GROUP
|
||||
|
||||
from(zipTree(tasks.shadowJar.get().archiveFile))
|
||||
|
||||
destinationDirectory.set(layout.buildDirectory.dir("minecraftModLibs"))
|
||||
}
|
||||
tasks.assemble {
|
||||
dependsOn(minecraftModJar)
|
||||
}
|
||||
|
||||
val minecraftModSourcesJar = tasks.register<Jar>("minecraftModSourcesJar") {
|
||||
group = LifecycleBasePlugin.BUILD_GROUP
|
||||
|
||||
from(zipTree(tasks.named<Jar>("sourcesJar").get().archiveFile))
|
||||
|
||||
archiveClassifier = "sources"
|
||||
destinationDirectory.set(layout.buildDirectory.dir("minecraftModLibs"))
|
||||
}
|
||||
|
||||
artifacts.add("minecraftModElements", minecraftModJar)
|
||||
artifacts.add("minecraftModSourcesElements", minecraftModSourcesJar)
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
create<MavenPublication>("minecraftMod") {
|
||||
groupId = "${project.group}.minecraft"
|
||||
artifactId = project.name
|
||||
version = project.version.toString()
|
||||
|
||||
from(components["minecraftMod"])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
plugins {
|
||||
java
|
||||
id("de.siphalor.tweed5.minecraft.mod.base")
|
||||
}
|
||||
|
||||
val processMinecraftModResources = tasks.register<Copy>("processMinecraftModResources") {
|
||||
from(project.layout.settingsDirectory.dir("minecraft/mod-template/resources"))
|
||||
expand(
|
||||
"id" to project.name,
|
||||
"version" to project.version,
|
||||
"name" to properties["minecraft.mod.name"],
|
||||
"description" to properties["minecraft.mod.description"]
|
||||
)
|
||||
into(project.layout.buildDirectory.dir("minecraftModResources"))
|
||||
}
|
||||
|
||||
tasks.named<Jar>("minecraftModJar") {
|
||||
from(project.layout.buildDirectory.dir("minecraftModResources"))
|
||||
dependsOn(processMinecraftModResources)
|
||||
}
|
||||
|
||||
tasks.named<Jar>("minecraftModSourcesJar") {
|
||||
from(project.layout.buildDirectory.dir("minecraftModResources"))
|
||||
dependsOn(processMinecraftModResources)
|
||||
}
|
||||
Reference in New Issue
Block a user