build: Rename all Gradle build logic modules to build-logic
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
plugins {
|
||||
`kotlin-dsl`
|
||||
`java-gradle-plugin`
|
||||
}
|
||||
|
||||
group = "de.siphalor.tweed5"
|
||||
|
||||
gradlePlugin {
|
||||
plugins.register("minecraftModComponent") {
|
||||
id = "de.siphalor.tweed5.minecraft.mod.component"
|
||||
implementationClass = "de.siphalor.tweed5.gradle.plugin.minecraft.mod.MinecraftModComponentPlugin"
|
||||
}
|
||||
plugins.register("moduleInfo") {
|
||||
id = "de.siphalor.tweed5.module-info"
|
||||
implementationClass = "de.siphalor.tweed5.gradle.plugin.module_info.ModuleInfoPlugin"
|
||||
}
|
||||
plugins.register("rootProperties") {
|
||||
id = "de.siphalor.tweed5.root-properties"
|
||||
implementationClass = "de.siphalor.tweed5.gradle.plugin.root_properties.RootPropertiesPlugin"
|
||||
}
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
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.EMBEDDED))
|
||||
attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.JAVA_RUNTIME))
|
||||
|
||||
project.afterEvaluate {
|
||||
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, targetJvmVersion.get().toInt())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val modApiElementsConfiguration = project.configurations.consumable("minecraftModApiElements") {
|
||||
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.EXTERNAL))
|
||||
attribute(Usage.USAGE_ATTRIBUTE, objectFactory.named(Usage.JAVA_API))
|
||||
|
||||
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(modApiElementsConfiguration.get()) {
|
||||
mapToMavenScope("compile")
|
||||
}
|
||||
modComponent.addVariantsFromConfiguration(modSourcesElementsConfiguration.get()) {
|
||||
mapToOptional()
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -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"
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package de.siphalor.tweed5.gradle.plugin.module_info
|
||||
|
||||
import org.gradle.api.provider.Property
|
||||
|
||||
abstract class ModuleInfoExtension {
|
||||
abstract val name: Property<String>
|
||||
abstract val description: Property<String>
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package de.siphalor.tweed5.gradle.plugin.module_info
|
||||
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
|
||||
class ModuleInfoPlugin : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
target.extensions.create("moduleInfo", ModuleInfoExtension::class.java)
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package de.siphalor.tweed5.gradle.plugin
|
||||
|
||||
import org.gradle.api.provider.MapProperty
|
||||
import org.gradle.api.provider.Provider
|
||||
|
||||
abstract class RootPropertiesExtension {
|
||||
abstract val properties: MapProperty<String, String>
|
||||
|
||||
operator fun get(key: String): Provider<String> = properties.getting(key)
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
package de.siphalor.tweed5.gradle.plugin.root_properties
|
||||
|
||||
import de.siphalor.tweed5.gradle.plugin.RootPropertiesExtension
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.provider.ProviderFactory
|
||||
import org.gradle.kotlin.dsl.apply
|
||||
import java.util.Properties
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class RootPropertiesPlugin : Plugin<Project> {
|
||||
@get:Inject
|
||||
abstract val providers: ProviderFactory
|
||||
|
||||
override fun apply(project: Project) {
|
||||
val rootPropertiesFile = if (project.layout.settingsDirectory.file(".gitmodules").asFile.exists()) {
|
||||
project.layout.settingsDirectory.file("gradle.properties")
|
||||
} else {
|
||||
project.layout.settingsDirectory.file("../gradle.properties")
|
||||
}
|
||||
|
||||
val rootProperties = providers.fileContents(rootPropertiesFile).asBytes.map { propsBytes ->
|
||||
Properties().apply {
|
||||
load(propsBytes.inputStream())
|
||||
}.map { it.key.toString() to it.value.toString() }.toMap()
|
||||
}
|
||||
|
||||
project.extensions.create("rootProperties", RootPropertiesExtension::class.java).apply {
|
||||
properties.value(rootProperties)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user