Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create plugin for Scala publishing conventions #169

Merged
merged 5 commits into from
Jun 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ plugins {
repositories {
mavenCentral()
gradlePluginPortal()
}
}
15 changes: 0 additions & 15 deletions buildSrc/src/main/kotlin/ScalaDocumentationPlugin.kt

This file was deleted.

75 changes: 75 additions & 0 deletions buildSrc/src/main/kotlin/ScalaPublishingConventionsPlugin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.BasePlugin
import org.gradle.api.plugins.BasePluginExtension
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.register
import org.gradle.plugins.signing.SigningExtension

class ScalaPublishingConventionsPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run {
val scaladocJarTask: TaskProvider<Jar> = tasks.register<Jar>("scaladocJar") {
group = BasePlugin.BUILD_GROUP
tasks.findByName("scaladoc")?.let { dependsOn(it) }
franciscodr marked this conversation as resolved.
Show resolved Hide resolved
archiveClassifier.set("javadoc")
from("$buildDir/docs/scaladoc")
}

extensions.configure(PublishingExtension::class.java) {
publications {
register("maven", MavenPublication::class) {
val scala3Suffix = "_3"
from(components["java"])
artifact(scaladocJarTask)

extensions.findByType(BasePluginExtension::class.java)?.let {
artifactId = it.archivesName.get() + scala3Suffix
}

pom {
name.set(project.properties["pom.name"]?.toString())
description.set(project.properties["pom.description"]?.toString())
url.set(project.properties["pom.url"]?.toString())

licenses {
license {
name.set(project.properties["pom.license.name"]?.toString())
url.set(project.properties["pom.license.url"]?.toString())
}
}

developers {
developer {
id.set(project.properties["pom.developer.id"].toString())
name.set(project.properties["pom.developer.name"].toString())
}
}

scm {
url.set(project.properties["pom.smc.url"].toString())
connection.set(project.properties["pom.smc.connection"].toString())
developerConnection.set(project.properties["pom.smc.developerConnection"].toString())
}
}
}
}
}

extensions.configure(SigningExtension::class.java) {
val isLocal = gradle.startParameter.taskNames.any { it.contains("publishToMavenLocal", ignoreCase = true) }
val signingKeyId: String? = System.getenv("SIGNING_KEY_ID")
val signingKey: String? = System.getenv("SIGNING_KEY")
val signingPassphrase: String? = System.getenv("SIGNING_KEY_PASSPHRASE")

isRequired = !isLocal
useGpgCmd()
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassphrase)
extensions.findByType(PublishingExtension::class.java)?.let { sign(it.publications) }
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
apply<ScalaPublishingConventionsPlugin>()
58 changes: 3 additions & 55 deletions scala-cats/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
signing
alias(libs.plugins.semver.gradle)
alias(libs.plugins.spotless)
`xef-scala-documentation`
`xef-scala-publishing-conventions`
}

dependencies {
Expand All @@ -18,10 +18,8 @@ dependencies {
}

java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
toolchain {
languageVersion = JavaLanguageVersion.of(11)
languageVersion.set(JavaLanguageVersion.of(11))
}
withSourcesJar()
}
Expand All @@ -34,58 +32,8 @@ tasks.withType<ScalaCompile> {
scalaCompileOptions.additionalParameters = listOf("-Wunused:all", "-Wvalue-discard")
}

publishing {
publications {
register<MavenPublication>("maven") {
val scala3Suffix = "_3"
from(components["java"])
artifact(tasks.named("scaladocJar"))

artifactId = base.archivesName.get() + scala3Suffix

pom {
name.set(project.properties["pom.name"]?.toString())
description.set(project.properties["pom.description"]?.toString())
url.set(project.properties["pom.url"]?.toString())

licenses {
license {
name.set(project.properties["pom.license.name"]?.toString())
url.set(project.properties["pom.license.url"]?.toString())
}
}

developers {
developer {
id.set(project.properties["pom.developer.id"].toString())
name.set(project.properties["pom.developer.name"].toString())
}
}

scm {
url.set(project.properties["pom.smc.url"].toString())
connection.set(project.properties["pom.smc.connection"].toString())
developerConnection.set(project.properties["pom.smc.developerConnection"].toString())
}
}
}
}
}

signing {
val isLocal = gradle.startParameter.taskNames.any { it.contains("publishToMavenLocal", ignoreCase = true) }
val signingKeyId: String? = System.getenv("SIGNING_KEY_ID")
val signingKey: String? = System.getenv("SIGNING_KEY")
val signingPassphrase: String? = System.getenv("SIGNING_KEY_PASSPHRASE")

isRequired = !isLocal
useGpgCmd()
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassphrase)
sign(publishing.publications)
}

spotless {
scala {
scalafmt("3.7.3").configFile(".scalafmt.conf").scalaMajorVersion("2.13")
}
}
}
54 changes: 2 additions & 52 deletions scala/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
signing
alias(libs.plugins.semver.gradle)
alias(libs.plugins.spotless)
`xef-scala-documentation`
`xef-scala-publishing-conventions`
}

dependencies {
Expand Down Expand Up @@ -40,58 +40,8 @@ tasks.withType<ScalaCompile> {
scalaCompileOptions.additionalParameters = listOf("-Wunused:all", "-Wvalue-discard")
}

publishing {
publications {
register<MavenPublication>("maven") {
val scala3Suffix = "_3"
from(components["java"])
artifact(tasks.named("scaladocJar"))

artifactId = base.archivesName.get() + scala3Suffix

pom {
name.set(project.properties["pom.name"]?.toString())
description.set(project.properties["pom.description"]?.toString())
url.set(project.properties["pom.url"]?.toString())

licenses {
license {
name.set(project.properties["pom.license.name"]?.toString())
url.set(project.properties["pom.license.url"]?.toString())
}
}

developers {
developer {
id.set(project.properties["pom.developer.id"].toString())
name.set(project.properties["pom.developer.name"].toString())
}
}

scm {
url.set(project.properties["pom.smc.url"].toString())
connection.set(project.properties["pom.smc.connection"].toString())
developerConnection.set(project.properties["pom.smc.developerConnection"].toString())
}
}
}
}
}

signing {
val isLocal = gradle.startParameter.taskNames.any { it.contains("publishToMavenLocal", ignoreCase = true) }
val signingKeyId: String? = System.getenv("SIGNING_KEY_ID")
val signingKey: String? = System.getenv("SIGNING_KEY")
val signingPassphrase: String? = System.getenv("SIGNING_KEY_PASSPHRASE")

isRequired = !isLocal
useGpgCmd()
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassphrase)
sign(publishing.publications)
}

spotless {
scala {
scalafmt("3.7.3").configFile(".scalafmt.conf").scalaMajorVersion("2.13")
}
}
}