From e6cf760879aa0401f7321d8dea97dd17ef7528e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Mon, 26 Aug 2024 14:51:54 +0300 Subject: [PATCH] simplify. --- build.gradle.kts | 4 +- .../main/kotlin/net/infumia/gradle/common.kt | 28 +++--------- .../main/kotlin/net/infumia/gradle/publish.kt | 43 +++++++++++-------- .../kotlin/net/infumia/gradle/spotless.kt | 2 +- common/build.gradle.kts | 4 +- kotlin/coroutines/build.gradle.kts | 4 +- kotlin/extensions/build.gradle.kts | 4 +- redis/build.gradle.kts | 4 +- 8 files changed, 42 insertions(+), 51 deletions(-) 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 index 6286f5f..9a32fba 100644 --- a/buildSrc/src/main/kotlin/net/infumia/gradle/common.kt +++ b/buildSrc/src/main/kotlin/net/infumia/gradle/common.kt @@ -3,12 +3,12 @@ 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.* import org.jetbrains.dokka.gradle.DokkaPlugin -fun Project.applyCommon(javaVersion: Int = 8, sources: Boolean = true, javadoc: Boolean = true) { +fun Project.applyCommon(javaVersion: Int = 8) { apply() if (name.contains("kotlin")) { @@ -19,25 +19,9 @@ fun Project.applyCommon(javaVersion: Int = 8, sources: Boolean = true, javadoc: repositories.mavenCentral() extensions.configure { - toolchain { languageVersion = JavaLanguageVersion.of(javaVersion) } - } - - 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) - } + 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 a0a7389..f08efc0 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) { + applyCommon(javaVersion) apply() val projectName = "lock${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("") - url.set("https://github.com/Infumia/lock") + name = projectName + description = "" + url = "https://github.com/Infumia/lock" 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/lock.git") - developerConnection.set("scm:git:ssh://github.com/infumia/lock.git") - url.set("https://github.com/infumia/lock/") + connection = "scm:git:git://github.com/infumia/lock.git" + developerConnection = "scm:git:ssh://github.com/infumia/lock.git" + url = "https://github.com/infumia/lock/" } } } diff --git a/buildSrc/src/main/kotlin/net/infumia/gradle/spotless.kt b/buildSrc/src/main/kotlin/net/infumia/gradle/spotless.kt index 95553c9..e2e1a26 100644 --- a/buildSrc/src/main/kotlin/net/infumia/gradle/spotless.kt +++ b/buildSrc/src/main/kotlin/net/infumia/gradle/spotless.kt @@ -5,7 +5,7 @@ import com.diffplug.gradle.spotless.SpotlessPlugin 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() diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 09a75ea..155c1e4 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 {} diff --git a/kotlin/coroutines/build.gradle.kts b/kotlin/coroutines/build.gradle.kts index 5d01f9d..5afc2df 100644 --- a/kotlin/coroutines/build.gradle.kts +++ b/kotlin/coroutines/build.gradle.kts @@ -1,6 +1,6 @@ -import net.infumia.gradle.publish +import net.infumia.gradle.applyPublish -publish("kotlin-coroutines") +applyPublish("kotlin-coroutines") dependencies { compileOnly(project(":common")) diff --git a/kotlin/extensions/build.gradle.kts b/kotlin/extensions/build.gradle.kts index 634eacd..829893a 100644 --- a/kotlin/extensions/build.gradle.kts +++ b/kotlin/extensions/build.gradle.kts @@ -1,5 +1,5 @@ -import net.infumia.gradle.publish +import net.infumia.gradle.applyPublish -publish("kotlin") +applyPublish("kotlin") dependencies { compileOnly(project(":common")) } diff --git a/redis/build.gradle.kts b/redis/build.gradle.kts index 9ec2cfc..d48bab0 100644 --- a/redis/build.gradle.kts +++ b/redis/build.gradle.kts @@ -1,6 +1,6 @@ -import net.infumia.gradle.publish +import net.infumia.gradle.applyPublish -publish("redis") +applyPublish("redis") dependencies { compileOnly(project(":common"))