diff --git a/build.gradle.kts b/build.gradle.kts index e905e78..ea8ee3d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,14 +1,14 @@ -import net.infumia.gradle.protobuf -import net.infumia.gradle.publish -import net.infumia.gradle.spotless +import net.infumia.gradle.applyProtobuf +import net.infumia.gradle.applyPublish +import net.infumia.gradle.applySpotless plugins { java } -publish() +applyPublish() -protobuf() +applyProtobuf() -spotless() +applySpotless() dependencies { compileOnly(libs.protobuf) diff --git a/buildSrc/src/main/kotlin/net/infumia/gradle/common.kt b/buildSrc/src/main/kotlin/net/infumia/gradle/common.kt index bf30016..8ba78b2 100644 --- a/buildSrc/src/main/kotlin/net/infumia/gradle/common.kt +++ b/buildSrc/src/main/kotlin/net/infumia/gradle/common.kt @@ -4,12 +4,11 @@ import org.gradle.api.Project import org.gradle.api.file.DuplicatesStrategy 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.kotlin.dsl.* import org.gradle.language.jvm.tasks.ProcessResources -fun Project.applyCommon(javaVersion: Int = 8, sources: Boolean = true, javadoc: Boolean = true) { +fun Project.applyJava(javaVersion: Int = 8) { apply() repositories.mavenCentral() @@ -18,25 +17,5 @@ fun Project.applyCommon(javaVersion: Int = 8, sources: Boolean = true, javadoc: 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) - duplicatesStrategy = DuplicatesStrategy.EXCLUDE - } - } - tasks { withType { duplicatesStrategy = DuplicatesStrategy.EXCLUDE } } } diff --git a/buildSrc/src/main/kotlin/net/infumia/gradle/protobuf.kt b/buildSrc/src/main/kotlin/net/infumia/gradle/protobuf.kt index 5774db0..958e4cb 100644 --- a/buildSrc/src/main/kotlin/net/infumia/gradle/protobuf.kt +++ b/buildSrc/src/main/kotlin/net/infumia/gradle/protobuf.kt @@ -9,7 +9,7 @@ import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.tasks.javadoc.Javadoc import org.gradle.kotlin.dsl.* -fun Project.protobuf() { +fun Project.applyProtobuf() { val libs = project.rootProject.the() apply() diff --git a/buildSrc/src/main/kotlin/net/infumia/gradle/publish.kt b/buildSrc/src/main/kotlin/net/infumia/gradle/publish.kt index d0241a8..fe4e93a 100644 --- a/buildSrc/src/main/kotlin/net/infumia/gradle/publish.kt +++ b/buildSrc/src/main/kotlin/net/infumia/gradle/publish.kt @@ -3,21 +3,30 @@ 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.file.DuplicatesStrategy +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 = "agones4j${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) + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + } + + tasks.withType { afterEvaluate { archiveBaseName = name } } + extensions.configure { coordinates(project.group.toString(), projectName, project.version.toString()) publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL, true) @@ -26,26 +35,26 @@ fun Project.publish( } pom { - name.set("Agones4J") - description.set("Java wrapper for Agones client SDK.") - url.set("https://infumia.com.tr/") + name = "Agones4J" + description = "Java wrapper for Agones client SDK." + url = "https://infumia.com.tr/" 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/agones4j.git") - developerConnection.set("scm:git:ssh://github.com/infumia/agones4j.git") - url.set("https://github.com/infumia/agones4j") + connection = "scm:git:git://github.com/infumia/agones4j.git" + developerConnection = "scm:git:ssh://github.com/infumia/agones4j.git" + url = "https://github.com/infumia/agones4j" } } } diff --git a/buildSrc/src/main/kotlin/net/infumia/gradle/spotless.kt b/buildSrc/src/main/kotlin/net/infumia/gradle/spotless.kt index cdb2e16..270d0ef 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() { repositories.mavenCentral() apply()