diff --git a/blank/build.gradle.kts b/blank/build.gradle.kts index 05d7dad..ff2f859 100644 --- a/blank/build.gradle.kts +++ b/blank/build.gradle.kts @@ -1,6 +1,6 @@ -import net.infumia.gradle.publish +import net.infumia.gradle.applyPublish -publish("blank") +applyPublish("blank") dependencies { compileOnly(project(":common")) diff --git a/build.gradle.kts b/build.gradle.kts index ff3dd55..467db0e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,7 +1,7 @@ -import net.infumia.gradle.spotless +import net.infumia.gradle.applySpotless plugins { java } subprojects { apply() } -spotless() +applySpotless() diff --git a/buildSrc/src/main/kotlin/net/infumia/gradle/common.kt b/buildSrc/src/main/kotlin/net/infumia/gradle/common.kt deleted file mode 100644 index 7ef5b89..0000000 --- a/buildSrc/src/main/kotlin/net/infumia/gradle/common.kt +++ /dev/null @@ -1,41 +0,0 @@ -package net.infumia.gradle - -import org.gradle.api.Project -import org.gradle.api.plugins.JavaPlugin -import org.gradle.api.plugins.JavaPluginExtension -import org.gradle.api.tasks.bundling.Jar -import org.gradle.jvm.toolchain.JavaLanguageVersion -import org.gradle.jvm.toolchain.JvmVendorSpec -import org.gradle.kotlin.dsl.* - -fun Project.applyCommon(javaVersion: Int = 8, sources: Boolean = true, javadoc: Boolean = true) { - apply() - - repositories.mavenCentral() - - extensions.configure { - toolchain { - languageVersion = JavaLanguageVersion.of(javaVersion) - vendor = JvmVendorSpec.ADOPTIUM - } - } - - if (javadoc) { - val javadocJar by - tasks.creating(Jar::class) { - dependsOn("javadoc") - archiveClassifier.set("javadoc") - from(javadoc) - } - } - - if (sources) { - val sourceSets = extensions.getByType().sourceSets - val sourcesJar by - tasks.creating(Jar::class) { - dependsOn("classes") - archiveClassifier.set("sources") - from(sourceSets["main"].allSource) - } - } -} diff --git a/buildSrc/src/main/kotlin/net/infumia/gradle/java.kt b/buildSrc/src/main/kotlin/net/infumia/gradle/java.kt new file mode 100644 index 0000000..0b1bdfc --- /dev/null +++ b/buildSrc/src/main/kotlin/net/infumia/gradle/java.kt @@ -0,0 +1,21 @@ +package net.infumia.gradle + +import org.gradle.api.Project +import org.gradle.api.plugins.JavaPlugin +import org.gradle.api.plugins.JavaPluginExtension +import org.gradle.jvm.toolchain.JavaLanguageVersion +import org.gradle.jvm.toolchain.JvmVendorSpec +import org.gradle.kotlin.dsl.* + +fun Project.applyJava(javaVersion: Int = 8) { + apply() + + repositories.mavenCentral() + + extensions.configure { + toolchain { + languageVersion = JavaLanguageVersion.of(javaVersion) + vendor = JvmVendorSpec.ADOPTIUM + } + } +} diff --git a/buildSrc/src/main/kotlin/net/infumia/gradle/publish.kt b/buildSrc/src/main/kotlin/net/infumia/gradle/publish.kt index 25b2cc8..98ccd4f 100644 --- a/buildSrc/src/main/kotlin/net/infumia/gradle/publish.kt +++ b/buildSrc/src/main/kotlin/net/infumia/gradle/publish.kt @@ -3,21 +3,28 @@ package net.infumia.gradle import com.vanniktech.maven.publish.MavenPublishBaseExtension import com.vanniktech.maven.publish.MavenPublishPlugin import com.vanniktech.maven.publish.SonatypeHost +import com.vanniktech.maven.publish.tasks.JavadocJar import org.gradle.api.Project +import org.gradle.api.plugins.JavaPluginExtension +import org.gradle.api.tasks.bundling.Jar import org.gradle.kotlin.dsl.* -fun Project.publish( - moduleName: String? = null, - javaVersion: Int = 8, - sources: Boolean = true, - javadoc: Boolean = true -) { - applyCommon(javaVersion, sources, javadoc) +fun Project.applyPublish(moduleName: String? = null, javaVersion: Int = 8) { + applyJava(javaVersion) apply() val projectName = "pack${if (moduleName == null) "" else "-$moduleName"}" val signRequired = project.hasProperty("sign-required") + val sourceSets = extensions.getByType().sourceSets + tasks.register("sourcesJar", Jar::class) { + dependsOn("classes") + archiveClassifier = "sources" + from(sourceSets["main"].allSource) + } + + tasks.withType { afterEvaluate { archiveBaseName = name } } + extensions.configure { coordinates(project.group.toString(), projectName, project.version.toString()) publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, true) @@ -26,26 +33,26 @@ fun Project.publish( } pom { - name.set(projectName) - description.set("Minecraft resource pack generator.") - url.set("https://github.com/Infumia/pack") + name = projectName + description = "Minecraft resource pack generator." + url = "https://github.com/Infumia/pack" licenses { license { - name.set("MIT License") - url.set("https://mit-license.org/license.txt") + name = "MIT License" + url = "https://mit-license.org/license.txt" } } developers { developer { - id.set("portlek") - name.set("Hasan Demirtaş") - email.set("utsukushihito@outlook.com") + id = "portlek" + name = "Hasan Demirtaş" + email = "utsukushihito@outlook.com" } } scm { - connection.set("scm:git:git://github.com/infumia/pack.git") - developerConnection.set("scm:git:ssh://github.com/infumia/pack.git") - url.set("https://github.com/infumia/pack/") + connection = "scm:git:git://github.com/infumia/pack.git" + developerConnection = "scm:git:ssh://github.com/infumia/pack.git" + url = "https://github.com/infumia/pack/" } } } diff --git a/buildSrc/src/main/kotlin/net/infumia/gradle/spotless.kt b/buildSrc/src/main/kotlin/net/infumia/gradle/spotless.kt index 95553c9..52316eb 100644 --- a/buildSrc/src/main/kotlin/net/infumia/gradle/spotless.kt +++ b/buildSrc/src/main/kotlin/net/infumia/gradle/spotless.kt @@ -2,10 +2,11 @@ package net.infumia.gradle import com.diffplug.gradle.spotless.SpotlessExtension import com.diffplug.gradle.spotless.SpotlessPlugin +import com.diffplug.spotless.LineEnding import org.gradle.api.Project import org.gradle.kotlin.dsl.* -fun Project.spotless() { +fun Project.applySpotless() { val subProjects = subprojects.map { it.projectDir.toRelativeString(projectDir) } repositories.mavenCentral() @@ -14,7 +15,7 @@ fun Project.spotless() { extensions.configure { isEnforceCheck = false - lineEndings = com.diffplug.spotless.LineEnding.UNIX + lineEndings = LineEnding.UNIX val prettierConfig = mapOf( diff --git a/common/build.gradle.kts b/common/build.gradle.kts index a9b4c70..c3573c6 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,5 +1,5 @@ -import net.infumia.gradle.publish +import net.infumia.gradle.applyPublish -publish() +applyPublish() dependencies { compileOnly(libs.creative.api) } diff --git a/generator/build.gradle.kts b/generator/build.gradle.kts index acbe1ba..55234a1 100644 --- a/generator/build.gradle.kts +++ b/generator/build.gradle.kts @@ -1,6 +1,6 @@ -import net.infumia.gradle.publish +import net.infumia.gradle.applyPublish -publish("generator") +applyPublish("generator") dependencies { compileOnly(project(":common")) diff --git a/language/build.gradle.kts b/language/build.gradle.kts index 0caefcb..ee9a829 100644 --- a/language/build.gradle.kts +++ b/language/build.gradle.kts @@ -1,6 +1,6 @@ -import net.infumia.gradle.publish +import net.infumia.gradle.applyPublish -publish("language") +applyPublish("language") dependencies { compileOnly(project(":common"))