From 3052bed92752a0aeff51046eb75aae1ed6fac221 Mon Sep 17 00:00:00 2001 From: Dimitris ZARRAS <138439389+dzarras@users.noreply.github.com> Date: Fri, 13 Oct 2023 12:43:59 +0300 Subject: [PATCH] Configure and use com.vanniktech.maven.publish for Maven publications (#81) --- .github/workflows/ci.yml | 12 ++-- .github/workflows/release.yml | 12 ++-- build.gradle.kts | 113 +++++----------------------------- gradle.properties | 24 +++++++- gradle/libs.versions.toml | 8 +-- 5 files changed, 53 insertions(+), 116 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7cf5d36..228656f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,13 +45,13 @@ jobs: - name: Publish with Gradle Wrapper uses: gradle/gradle-build-action@v2.8.1 with: - arguments: publish --full-stacktrace + arguments: publishAllPublicationsToMavenCentral --full-stacktrace env: CI: true GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.OSSRH_GPG_KEY_ID }} - ORG_GRADLE_PROJECT_signingKey: ${{ secrets.OSSRH_GPG_SECRET_KEY }} - ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.OSSRH_GPG_PASSPHRASE }} - ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.OSSRH_USERNAME }} - ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.OSSRH_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.OSSRH_GPG_KEY_ID }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.OSSRH_GPG_SECRET_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.OSSRH_GPG_PASSPHRASE }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }} GIT_REF_NAME: ${{ github.ref_name }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4f36e8d..04f63d5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,13 +24,13 @@ jobs: uses: gradle/gradle-build-action@v2.8.1 with: gradle-version: wrapper - arguments: build publish --full-stacktrace + arguments: build publishAllPublicationsToMavenCentral --no-configuration-cache --full-stacktrace env: CI: true GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.OSSRH_GPG_KEY_ID }} - ORG_GRADLE_PROJECT_signingKey: ${{ secrets.OSSRH_GPG_SECRET_KEY }} - ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.OSSRH_GPG_PASSPHRASE }} - ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.OSSRH_USERNAME }} - ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.OSSRH_PASSWORD }} + ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.OSSRH_GPG_KEY_ID }} + ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.OSSRH_GPG_SECRET_KEY }} + ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.OSSRH_GPG_PASSPHRASE }} + ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.OSSRH_USERNAME }} + ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.OSSRH_PASSWORD }} GIT_REF_NAME: ${{ github.ref_name }} diff --git a/build.gradle.kts b/build.gradle.kts index d5dc4df..387c079 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,13 +1,14 @@ import org.jetbrains.dokka.DokkaConfiguration.Visibility import org.jetbrains.dokka.gradle.DokkaTask import java.net.URL -import kotlin.jvm.optionals.getOrNull + +object Meta { + const val BASE_URL = "https://github.com/eu-digital-identity-wallet/eudi-lib-jvm-presentation-exchange-kt" +} plugins { base `java-library` - `maven-publish` - signing jacoco alias(libs.plugins.dokka) alias(libs.plugins.kotlin.jvm) @@ -15,10 +16,9 @@ plugins { alias(libs.plugins.spotless) alias(libs.plugins.sonarqube) alias(libs.plugins.dependencycheck) + alias(libs.plugins.maven.publish) } -extra["isReleaseVersion"] = !version.toString().endsWith("SNAPSHOT") - repositories { mavenCentral() mavenLocal() @@ -32,13 +32,13 @@ dependencies { } java { - withSourcesJar() - val javaVersion = getVersionFromCatalog("java") + val javaVersion = libs.versions.java.get() sourceCompatibility = JavaVersion.toVersion(javaVersion) } + kotlin { jvmToolchain { - val javaVersion = getVersionFromCatalog("java") + val javaVersion = libs.versions.java.get() languageVersion.set(JavaLanguageVersion.of(javaVersion)) } } @@ -62,15 +62,6 @@ tasks.jar { } } -// -// Redefine javadocJar in terms of Dokka -// -val javadocJar = tasks.register("javadocJar") { - dependsOn(tasks.dokkaHtml) - from(tasks.dokkaHtml.flatMap { it.outputDirectory }) - archiveClassifier.set("javadoc") -} - // // Configuration of Dokka engine // @@ -85,7 +76,7 @@ tasks.withType().configureEach { documentedVisibilities.set(setOf(Visibility.PUBLIC, Visibility.PROTECTED)) - val remoteSourceUrl = System.getenv()["GIT_REF_NAME"]?.let { URL("${Meta.PROJ_BASE_DIR}/tree/$it/src") } + val remoteSourceUrl = System.getenv()["GIT_REF_NAME"]?.let { URL("${Meta.BASE_URL}/tree/$it/src") } remoteSourceUrl ?.let { sourceLink { @@ -105,7 +96,7 @@ tasks.jacocoTestReport { } spotless { - val ktlintVersion = getVersionFromCatalog("ktlintVersion") + val ktlintVersion = libs.versions.ktlint.get() kotlin { ktlint(ktlintVersion) licenseHeaderFile("FileHeader.txt") @@ -115,85 +106,11 @@ spotless { } } -object Meta { - const val ORG_URL = "https://github.com/eu-digital-identity-wallet" - const val PROJ_DESCR = "Implementation of Presentation Exchange v2" - const val PROJ_BASE_DIR = "https://github.com/eu-digital-identity-wallet/eudi-lib-jvm-presentation-exchange-kt" - const val PROJ_GIT_URL = - "scm:git:git@github.com:eu-digital-identity-wallet/eudi-lib-jvm-presentation-exchange-kt.git" - const val PRJ_SSH_URL = - "scm:git:ssh://github.com:eu-digital-identity-wallet/eudi-lib-jvm-presentation-exchange-kt.git" -} -publishing { - - publications { - create("library") { - from(components["java"]) - artifacts + artifact(javadocJar) - pom { - name.set(project.name) - description.set(Meta.PROJ_DESCR) - url.set(Meta.PROJ_BASE_DIR) - licenses { - license { - name.set("The Apache License, Version 2.0") - url.set("https://www.apache.org/licenses/LICENSE-2.0.txt") - } - } - scm { - connection.set(Meta.PROJ_GIT_URL) - developerConnection.set(Meta.PRJ_SSH_URL) - url.set(Meta.PROJ_BASE_DIR) - } - issueManagement { - system.set("github") - url.set(Meta.PROJ_BASE_DIR + "/issues") - } - ciManagement { - system.set("github") - url.set(Meta.PROJ_BASE_DIR + "/actions") - } - developers { - organization { - url.set(Meta.ORG_URL) - } - } - } +mavenPublishing { + pom { + ciManagement { + system = "github" + url = "${Meta.BASE_URL}/actions" } } - repositories { - - val sonaUri = - if ((extra["isReleaseVersion"]) as Boolean) { - "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" - } else { - "https://s01.oss.sonatype.org/content/repositories/snapshots/" - } - - maven { - name = "sonatype" - url = uri(sonaUri) - credentials(PasswordCredentials::class) - } - } -} - -signing { - setRequired({ - (project.extra["isReleaseVersion"] as Boolean) && gradle.taskGraph.hasTask("publish") - }) - val signingKeyId: String? by project - val signingKey: String? by project - val signingPassword: String? by project - useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword) - sign(publishing.publications["library"]) -} - -fun getVersionFromCatalog(lookup: String): String { - val versionCatalog: VersionCatalog = extensions.getByType().named("libs") - return versionCatalog - .findVersion(lookup) - .getOrNull() - ?.requiredVersion - ?: throw GradleException("Version '$lookup' is not specified in the version catalog") } diff --git a/gradle.properties b/gradle.properties index a193794..c5b9b7e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,13 +1,35 @@ # Gradle options org.gradle.jvmargs=-Xmx4g org.gradle.parallel=true + # Kotlin configuration kotlin.incremental=true kotlin.code.style=official - +# Project properties group=eu.europa.ec.eudi version=0.1.0-SNAPSHOT # Sonar systemProp.sonar.host.url=https://sonarcloud.io + +# Maven publishing properties +SONATYPE_HOST=S01 +SONATYPE_AUTOMATIC_RELEASE=false +RELEASE_SIGNING_ENABLED=true + +POM_NAME=EUDI Presentation Exchange v2 library +POM_DESCRIPTION=Implementation of Presentation Exchange v2 +POM_URL=https://github.com/eu-digital-identity-wallet/eudi-lib-jvm-presentation-exchange-kt + +POM_LICENSE_NAME=The Apache License, Version 2.0 +POM_LICENSE_URL=https://www.apache.org/licenses/LICENSE-2.0.txt + +POM_SCM_URL=https://github.com/eu-digital-identity-wallet/eudi-lib-jvm-presentation-exchange-kt +POM_SCM_CONNECTION=scm:git:git@github.com:eu-digital-identity-wallet/eudi-lib-jvm-presentation-exchange-kt.git +POM_SCM_DEV_CONNECTION=scm:git:ssh://github.com:eu-digital-identity-wallet/eudi-lib-jvm-presentation-exchange-kt.git + +POM_ISSUE_SYSTEM=github +POM_ISSUE_URL=https://github.com/eu-digital-identity-wallet/eudi-lib-jvm-presentation-exchange-kt/issues + +POM_DEVELOPER_URL=https://github.com/eu-digital-identity-wallet diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index de0d0b6..d89ab9f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,11 +7,12 @@ spotless = "6.21.0" java = "17" kotlinxSerialization = "1.6.0" nimbusJoseWwt = "9.35" -ktlintVersion = "0.50.0" +ktlint = "0.50.0" sonarqube = "4.3.1.3277" dependencycheck = "8.4.0" jsonKotlinSchema = "0.41" jsonpathkt="2.0.1" +mavenPublish="0.25.3" [libraries] kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerialization" } @@ -19,8 +20,6 @@ nimbus-jose-jwt = { module = "com.nimbusds:nimbus-jose-jwt", version.ref = "nimb json-kotlin-schema = { module = "net.pwall.json:json-kotlin-schema", version.ref = "jsonKotlinSchema" } jsonpathkt = { module = "com.nfeld.jsonpathkt:jsonpathkt", version.ref = "jsonpathkt" } - - [plugins] foojay-resolver-convention = { id = "org.gradle.toolchains.foojay-resolver-convention", version.ref = "foojay" } dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } @@ -29,5 +28,4 @@ kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-plugin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } dependencycheck = { id = "org.owasp.dependencycheck", version.ref = "dependencycheck" } sonarqube = { id = "org.sonarqube", version.ref = "sonarqube" } - - +maven-publish = { id = "com.vanniktech.maven.publish", version.ref="mavenPublish" }