mirror of
https://github.com/Jozufozu/Flywheel.git
synced 2025-01-24 11:57:54 +01:00
All your script are belong to us
- Port java/subproject convention plugins to kotlin binary plugin - Fix licence bundling in jars - Update licence year
This commit is contained in:
parent
069679689f
commit
a44e7f5205
8 changed files with 187 additions and 135 deletions
|
@ -1,4 +1,4 @@
|
|||
Copyright (c) 2021-2023 Jozufozu
|
||||
Copyright (c) 2021-2024 Jozufozu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
plugins {
|
||||
id("groovy-gradle-plugin")
|
||||
id("java-gradle-plugin")
|
||||
kotlin("jvm") version "1.9.20"
|
||||
`kotlin-dsl`
|
||||
|
@ -36,6 +35,10 @@ gradlePlugin {
|
|||
id = "flywheel.transitive-source-sets"
|
||||
implementationClass = "com.jozufozu.gradle.transitive.TransitiveSourceSetsPlugin"
|
||||
}
|
||||
create("subprojectPlugin") {
|
||||
id = "flywheel.subproject"
|
||||
implementationClass = "com.jozufozu.gradle.subproject.SubprojectPlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
boolean dev = System.getenv('RELEASE') == null || System.getenv('RELEASE').equalsIgnoreCase('false')
|
||||
String buildNumber = System.getenv('BUILD_NUMBER')
|
||||
|
||||
group = 'com.jozufozu.flywheel'
|
||||
version = mod_version + (dev && buildNumber != null ? "-${buildNumber}" : '')
|
||||
|
||||
base {
|
||||
archivesName = "flywheel-${name}-${artifact_minecraft_version}"
|
||||
}
|
||||
|
||||
java {
|
||||
JavaVersion javaVersion = JavaVersion.toVersion(java_version)
|
||||
sourceCompatibility = javaVersion
|
||||
targetCompatibility = javaVersion
|
||||
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(java_version)
|
||||
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
|
||||
// make builds reproducible
|
||||
tasks.withType(AbstractArchiveTask).configureEach {
|
||||
preserveFileTimestamps = false
|
||||
reproducibleFileOrder = true
|
||||
}
|
||||
|
||||
// module metadata is often broken on multi-platform projects
|
||||
tasks.withType(GenerateModuleMetadata).configureEach {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
tasks.withType(JavaCompile).configureEach { JavaCompile javaCompile ->
|
||||
javaCompile.options.encoding = 'UTF-8'
|
||||
javaCompile.options.release = Integer.parseInt(java_version)
|
||||
javaCompile.options.compilerArgs = ['-Xdiags:verbose']
|
||||
}
|
||||
|
||||
tasks.withType(Jar).configureEach { Jar jar ->
|
||||
addLicense(jar)
|
||||
}
|
||||
|
||||
tasks.named('javadoc', Javadoc).configure { Javadoc javadoc ->
|
||||
javadoc.source sourceSets.main.allJava
|
||||
// prevent java 8's strict doclint for javadocs from failing builds
|
||||
javadoc.options.optionFiles(rootProject.file('javadoc-options.txt'))
|
||||
javadoc.options.encoding = 'UTF-8'
|
||||
}
|
||||
|
||||
static void addLicense(Jar jarTask) {
|
||||
jarTask.from('LICENSE.md') {
|
||||
rename '(.*)\\.(.*)', '$1_' + jarTask.archiveBaseName + '.$2'
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
loom {
|
||||
silentMojangMappingsLicense()
|
||||
|
||||
mixin {
|
||||
defaultRefmapName = "flywheel.refmap.json"
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
name = 'ParchmentMC'
|
||||
url = 'https://maven.parchmentmc.org'
|
||||
}
|
||||
maven {
|
||||
name 'tterrag maven'
|
||||
url 'https://maven.tterrag.com/'
|
||||
}
|
||||
maven {
|
||||
url 'https://www.cursemaven.com'
|
||||
content {
|
||||
includeGroup "curse.maven"
|
||||
}
|
||||
}
|
||||
maven {
|
||||
name = "Modrinth"
|
||||
url = "https://api.modrinth.com/maven"
|
||||
content {
|
||||
includeGroup "maven.modrinth"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:${minecraft_version}"
|
||||
mappings(loom.layered() {
|
||||
officialMojangMappings()
|
||||
parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip")
|
||||
})
|
||||
|
||||
api 'com.google.code.findbugs:jsr305:3.0.2'
|
||||
}
|
||||
|
||||
tasks.withType(ProcessResources).configureEach {
|
||||
var replaceProperties = [
|
||||
mod_id : mod_id,
|
||||
mod_name : mod_name,
|
||||
mod_description : mod_description,
|
||||
mod_license : mod_license,
|
||||
mod_sources : mod_sources,
|
||||
mod_issues : mod_issues,
|
||||
mod_homepage : mod_homepage,
|
||||
mod_version : mod_version,
|
||||
minecraft_semver_version_range: minecraft_semver_version_range,
|
||||
minecraft_maven_version_range : minecraft_maven_version_range,
|
||||
fabric_api_version_range : fabric_api_version_range,
|
||||
forge_version_range : forge_version_range,
|
||||
]
|
||||
inputs.properties replaceProperties
|
||||
|
||||
filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml']) {
|
||||
expand replaceProperties
|
||||
}
|
||||
}
|
||||
|
||||
publishing {
|
||||
repositories {
|
||||
maven {
|
||||
url "file://${rootProject.projectDir}/mcmodsrepo"
|
||||
}
|
||||
|
||||
if (project.hasProperty('mavendir')) {
|
||||
maven { url rootProject.file(property('mavendir')) }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,182 @@
|
|||
package com.jozufozu.gradle.subproject
|
||||
|
||||
import net.fabricmc.loom.api.LoomGradleExtensionAPI
|
||||
import org.gradle.api.JavaVersion
|
||||
import org.gradle.api.Plugin
|
||||
import org.gradle.api.Project
|
||||
import org.gradle.api.plugins.BasePluginExtension
|
||||
import org.gradle.api.plugins.JavaPluginExtension
|
||||
import org.gradle.api.publish.PublishingExtension
|
||||
import org.gradle.api.publish.tasks.GenerateModuleMetadata
|
||||
import org.gradle.api.tasks.bundling.AbstractArchiveTask
|
||||
import org.gradle.api.tasks.compile.JavaCompile
|
||||
import org.gradle.api.tasks.javadoc.Javadoc
|
||||
import org.gradle.jvm.tasks.Jar
|
||||
import org.gradle.jvm.toolchain.JavaLanguageVersion
|
||||
import org.gradle.kotlin.dsl.assign
|
||||
import org.gradle.kotlin.dsl.maven
|
||||
import org.gradle.kotlin.dsl.provideDelegate
|
||||
import org.gradle.kotlin.dsl.the
|
||||
import org.gradle.language.jvm.tasks.ProcessResources
|
||||
|
||||
|
||||
class SubprojectPlugin: Plugin<Project> {
|
||||
override fun apply(project: Project) {
|
||||
setBaseProperties(project)
|
||||
setupJava(project)
|
||||
addRepositories(project)
|
||||
setupLoom(project)
|
||||
setupDependencies(project)
|
||||
configureTasks(project)
|
||||
setupPublishing(project)
|
||||
}
|
||||
|
||||
private fun setBaseProperties(project: Project) {
|
||||
val dev = System.getenv("RELEASE")?.contentEquals("false", true) ?: true
|
||||
val buildNumber = System.getenv("BUILD_NUMBER")
|
||||
|
||||
val mod_version: String by project
|
||||
project.group = "com.jozufozu.flywheel"
|
||||
project.version = mod_version + if (dev && buildNumber != null) "-${buildNumber}" else ""
|
||||
|
||||
val artifact_minecraft_version: String by project
|
||||
project.the<BasePluginExtension>().archivesName = "flywheel-${project.name}-${artifact_minecraft_version}"
|
||||
}
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
private fun setupLoom(project: Project) {
|
||||
val loom = project.the<LoomGradleExtensionAPI>()
|
||||
loom.silentMojangMappingsLicense()
|
||||
|
||||
loom.mixin.defaultRefmapName = "flywheel.refmap.json"
|
||||
}
|
||||
|
||||
private fun setupJava(project: Project) {
|
||||
val java_version: String by project
|
||||
|
||||
project.the<JavaPluginExtension>().apply {
|
||||
val javaVersion = JavaVersion.toVersion(java_version)
|
||||
sourceCompatibility = javaVersion
|
||||
targetCompatibility = javaVersion
|
||||
|
||||
toolchain.languageVersion = JavaLanguageVersion.of(java_version)
|
||||
|
||||
withSourcesJar()
|
||||
withJavadocJar()
|
||||
}
|
||||
}
|
||||
|
||||
private fun addRepositories(project: Project) {
|
||||
project.repositories.apply {
|
||||
mavenCentral()
|
||||
maven("https://maven.parchmentmc.org") {
|
||||
name = "ParchmentMC"
|
||||
}
|
||||
maven("https://maven.tterrag.com/") {
|
||||
name = "tterrag maven"
|
||||
}
|
||||
maven("https://www.cursemaven.com") {
|
||||
name = "CurseMaven"
|
||||
content {
|
||||
includeGroup("curse.maven")
|
||||
}
|
||||
}
|
||||
maven("https://api.modrinth.com/maven") {
|
||||
name = "Modrinth"
|
||||
content {
|
||||
includeGroup("maven.modrinth")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("UnstableApiUsage")
|
||||
private fun setupDependencies(project: Project) {
|
||||
project.dependencies.apply {
|
||||
val minecraft_version: String by project
|
||||
val parchment_version: String by project
|
||||
val loom = project.the<LoomGradleExtensionAPI>()
|
||||
|
||||
add("minecraft", "com.mojang:minecraft:${minecraft_version}")
|
||||
|
||||
add("mappings", loom.layered {
|
||||
officialMojangMappings()
|
||||
parchment("org.parchmentmc.data:parchment-${minecraft_version}:${parchment_version}@zip")
|
||||
})
|
||||
|
||||
add("api", "com.google.code.findbugs:jsr305:3.0.2")
|
||||
}
|
||||
}
|
||||
|
||||
private fun configureTasks(project: Project) {
|
||||
val java_version: String by project
|
||||
|
||||
project.tasks.apply {
|
||||
// make builds reproducible
|
||||
withType(AbstractArchiveTask::class.java).configureEach {
|
||||
isPreserveFileTimestamps = false
|
||||
isReproducibleFileOrder = true
|
||||
}
|
||||
|
||||
// module metadata is often broken on multi-platform projects
|
||||
withType(GenerateModuleMetadata::class.java).configureEach {
|
||||
enabled = false
|
||||
}
|
||||
|
||||
withType(JavaCompile::class.java).configureEach {
|
||||
options.encoding = "UTF-8"
|
||||
options.release = Integer.parseInt(java_version)
|
||||
options.compilerArgs.add("-Xdiags:verbose")
|
||||
}
|
||||
|
||||
withType(Jar::class.java).configureEach {
|
||||
from("${project.rootDir}/LICENSE.md") {
|
||||
into("META-INF")
|
||||
}
|
||||
}
|
||||
|
||||
withType(Javadoc::class.java).configureEach {
|
||||
options.optionFiles(project.rootProject.file("javadoc-options.txt"))
|
||||
options.encoding = "UTF-8"
|
||||
}
|
||||
|
||||
val replaceProperties = processResourcesExpandProperties.associateWith { project.property(it) as String }
|
||||
|
||||
withType(ProcessResources::class.java).configureEach {
|
||||
inputs.properties(replaceProperties)
|
||||
|
||||
filesMatching(processResourcesExpandFiles) {
|
||||
expand(replaceProperties)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupPublishing(project: Project) {
|
||||
project.the<PublishingExtension>().repositories.apply {
|
||||
maven("file://${project.rootProject.projectDir}/mcmodsrepo")
|
||||
|
||||
if (project.hasProperty("mavendir")) {
|
||||
maven(project.rootProject.file(project.property("mavendir") as String))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val processResourcesExpandFiles = listOf("pack.mcmeta", "fabric.mod.json", "META-INF/mods.toml")
|
||||
|
||||
val processResourcesExpandProperties = listOf(
|
||||
"mod_id",
|
||||
"mod_name",
|
||||
"mod_description",
|
||||
"mod_license",
|
||||
"mod_sources",
|
||||
"mod_issues",
|
||||
"mod_homepage",
|
||||
"mod_version",
|
||||
"minecraft_semver_version_range",
|
||||
"minecraft_maven_version_range",
|
||||
"fabric_api_version_range",
|
||||
"forge_version_range",
|
||||
)
|
||||
|
|
@ -3,7 +3,6 @@ plugins {
|
|||
id 'java'
|
||||
id 'maven-publish'
|
||||
id 'dev.architectury.loom'
|
||||
id 'flywheel.java'
|
||||
id 'flywheel.package-infos'
|
||||
id 'flywheel.subproject'
|
||||
id 'flywheel.jar-sets'
|
||||
|
|
|
@ -3,7 +3,6 @@ plugins {
|
|||
id 'java'
|
||||
id 'maven-publish'
|
||||
id 'dev.architectury.loom'
|
||||
id 'flywheel.java'
|
||||
id 'flywheel.package-infos'
|
||||
id 'flywheel.subproject'
|
||||
id 'flywheel.platform'
|
||||
|
|
|
@ -3,7 +3,6 @@ plugins {
|
|||
id 'java'
|
||||
id 'maven-publish'
|
||||
id 'dev.architectury.loom'
|
||||
id 'flywheel.java'
|
||||
id 'flywheel.package-infos'
|
||||
id 'flywheel.subproject'
|
||||
id 'flywheel.platform'
|
||||
|
|
Loading…
Reference in a new issue