Skip to content

Commit

Permalink
Use gradle-nexus.publish-plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Legion2 committed Mar 25, 2024
1 parent 4baaf0c commit f020d0d
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 107 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,3 @@ jobs:
with:
job-id: jdk8-build-test
arguments: build -x test

- name: Publish Maven (Snapshot)
uses: burrunan/gradle-cache-action@v1
with:
job-id: jdk8-build-test
arguments: publishMavenRelease
properties: |
ossrhUsername=${{ secrets.OSSRH_USERNAME }}
ossrhPassword=${{ secrets.OSSRH_PASSWORD }}
12 changes: 5 additions & 7 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@ jobs:
- name: Publish Maven
uses: burrunan/gradle-cache-action@v1
env:
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.SIGNING_SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.SIGNING_PASSWORD }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
SIGNING_SIGNING_KEY: ${{ secrets.SIGNING_SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
with:
job-id: jdk8-build-test
arguments: >-
build
publishRelease
-x test
publishAllPublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
properties: |
releaseVersion=${{ steps.tagName.outputs.tag }}
ossrhUsername=${{ secrets.OSSRH_USERNAME }}
ossrhPassword=${{ secrets.OSSRH_PASSWORD }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@ gradle-app.setting

run
/.idea
/bin
bin/
91 changes: 1 addition & 90 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -108,112 +108,23 @@ tasks {
}
}


//
// DOCS
//

tasks {
dokkaHtml {
outputDirectory.set(file("$buildDir/javadoc/$releaseVersion"))
}

javadoc {
dependsOn(dokkaHtml)
}
}

//
// PUBLISHING
//

publishing {

publications {

create<MavenPublication>("library") {
create<MavenPublication>("maven") {
from(components["java"])

pom {
name.set("TypeScript Poet")
description.set("TypeScriptPoet is a Kotlin and Java API for generating .ts source files.")
url.set("https://github.com/voize-gmbh/typescriptpoet")

scm {
url.set("https://github.com/voize-gmbh/reakt-native-toolkit")
}

licenses {
license {
name.set("Apache-2.0")
url.set("https://opensource.org/licenses/Apache-2.0")
}
}
developers {
developer {
id.set("LeonKiefer")
name.set("Leon Kiefer")
email.set("[email protected]")
}
developer {
id.set("ErikZiegler")
name.set("Erik Ziegler")
email.set("[email protected]")
}
}
}
}
}

repositories {

maven {
name = "MavenCentral"
val snapshotUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
val releaseUrl = "https://s01.oss.sonatype.org/service/local/"
url = uri(if (isSnapshot) snapshotUrl else releaseUrl)

credentials {
username = project.findProperty("ossrhUsername")?.toString()
password = project.findProperty("ossrhPassword")?.toString()
}
}

}

}

signing {
if (!hasProperty("signing.keyId")) {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
}
sign(publishing.publications["library"])
}

tasks.withType<Sign>().configureEach {
onlyIf { !isSnapshot }
}


//
// RELEASING
//


tasks {

register("publishMavenRelease") {
dependsOn(
"publishAllPublicationsToMavenCentralRepository"
)
}

register("publishRelease") {
dependsOn(
"publishMavenRelease",
)
}

}
13 changes: 13 additions & 0 deletions convention-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
plugins {
`kotlin-dsl`
}

dependencies {
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.9.10")
implementation("io.github.gradle-nexus:publish-plugin:1.1.0")
}

repositories {
gradlePluginPortal()
mavenCentral()
}
113 changes: 113 additions & 0 deletions convention-plugins/src/main/kotlin/convention.publication.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import java.util.*

plugins {
`maven-publish`
signing
id("org.jetbrains.dokka")
id("io.github.gradle-nexus.publish-plugin")
}

val signingKey: String? = System.getenv("SIGNING_SIGNING_KEY")
val signingPassword: String? = System.getenv("SIGNING_PASSWORD")

// Stub secrets to let the project sync and build without the publication values set up
ext["ossrhUsername"] = null
ext["ossrhPassword"] = null

// Grabbing secrets from local.properties file or from environment variables, which could be used on CI
val secretPropsFile = project.rootProject.file("local.properties")
if (secretPropsFile.exists()) {
secretPropsFile.reader().use {
Properties().apply {
load(it)
}
}.onEach { (name, value) ->
ext[name.toString()] = value
}
} else {
ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")
}

fun getExtraString(name: String) = ext[name]?.toString()

nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username.set(getExtraString("ossrhUsername"))
password.set(getExtraString("ossrhPassword"))
}
}
}

subprojects {
apply(plugin = "org.jetbrains.dokka")
apply(plugin = "maven-publish")
apply(plugin = "signing")

tasks {
val dokkaOutputDir = "$buildDir/dokka"

dokkaHtml {
outputDirectory.set(file(dokkaOutputDir))
}
}

publishing {
// Configure all publications
publications.withType<MavenPublication> {
val publication = this
val dokkaJar = tasks.register<Jar>("${publication.name}DokkaJar") {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka into a Javadoc jar"
archiveClassifier.set("javadoc")
from(tasks.named("dokkaHtml"))
// Each archive name should be distinct, to avoid implicit dependency issues.
// We use the same format as the sources Jar tasks.
// https://youtrack.jetbrains.com/issue/KT-46466
archiveBaseName.set("${archiveBaseName.get()}-${publication.name}")
}

artifact(dokkaJar)

// Provide artifacts information required by Maven Central
pom {
url.set("https://github.com/voize-gmbh/typescriptpoet")

licenses {
license {
name.set("Apache-2.0")
url.set("https://opensource.org/licenses/Apache-2.0")
}
}
developers {
developer {
id.set("LeonKiefer")
name.set("Leon Kiefer")
email.set("[email protected]")
}
developer {
id.set("ErikZiegler")
name.set("Erik Ziegler")
email.set("[email protected]")
}
}
scm {
url.set("https://github.com/voize-gmbh/typescriptpoet")
}
}
}
}

if (signingPassword != null) {
signing {
if (signingKey != null) {
useInMemoryPgpKeys(signingKey, signingPassword)
}
sign(publishing.publications)
}
}
}

0 comments on commit f020d0d

Please sign in to comment.