diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index 5788d32..9f8105d 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -32,3 +32,6 @@ jobs: env: MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + ORG_GRADLE_PROJECT_signingKeyId: ${{ secrets.PGP_KEY_ID }} + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.PGP_SECRET_KEY }} + ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.PGP_PASSWORD }} diff --git a/java/core/build.gradle b/java/core/build.gradle index 8cfddff..506c18d 100644 --- a/java/core/build.gradle +++ b/java/core/build.gradle @@ -1,6 +1,7 @@ plugins { id 'brapi.schema-tools.java-conventions' id 'java-library' + id "signing" id 'maven-publish' } @@ -28,4 +29,81 @@ publishing { } } } -} \ No newline at end of file +} + +java { + withJavadocJar() + withSourcesJar() +} + +// ossrh requries signing https://central.sonatype.org/pages/requirements.html +// https://docs.gradle.org/current/userguide/signing_plugin.html +// this only configures signing if the key is found +// For signing you need to make signingKey and signingPassword available properties See https://docs.gradle.org/current/userguide/build_environment.html#sec:project_properties +// The following makes the key available via the Gradle Property signingKey +// export ORG_GRADLE_PROJECT_signingKey=`cat test-private.pgp` +// export ORG_GRADLE_PROJECT_signingPassword="password" +// After making the Gradle properties above available, you can try signing using +// ./gradlew signMavenPublication +// +// NOTE: If you are using the legacy publishing you need to sign using the info at https://docs.gradle.org/current/userguide/signing_plugin.html#sec:signing_pom_files +def hasSigningKey = project.hasProperty("signingKeyId") || project.hasProperty("signingKey") +if(hasSigningKey) { + sign(project) +} +void sign(Project project) { + project.signing { + required { project.gradle.taskGraph.hasTask("publish") } + def signingKeyId = project.findProperty("signingKeyId") + def signingKey = project.findProperty("signingKey") + def signingPassword = project.findProperty("signingPassword") + if (signingKeyId) { + useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword) + } else if (signingKey) { + useInMemoryPgpKeys(signingKey, signingPassword) + } + sign publishing.publications.maven + } +} + +// customize the pom so it complies to Maven central requirements https://central.sonatype.org/pages/requirements.html +// https://docs.gradle.org/current/userguide/maven_plugin.html#sec:maven_pom_generation +project.plugins.withType(MavenPublishPlugin).all { + PublishingExtension publishing = project.extensions.getByType(PublishingExtension) + publishing.publications.withType(MavenPublication).all { mavenPublication -> + mavenPublication.pom { + name = "${project.group}:${project.name}" + description = name + url = "https://github.com/plantbreeding/brapi-schema-tools" + licenses { + license { + name = "MIT License" + url = "https://github.com/plantbreeding/brapi-schema-tools?tab=MIT-1-ov-file" + } + } + developers { + developer { + id = "daveneti" + name = "Guy Davenport" + email = "guy@daveneti.com" + organization = "Daveneti" + organizationUrl = "http://daveneti.com" + timezone = "New Zealand Standard Time" + } + developer { + id = "BrapiCoordinatorSelby" + name = "Peter Selby" + email = "ps664@cornell.edu" + organization = "BrAPI" + organizationUrl = "https://brapi.org" + timezone = "Eastern Standard Time" + } + } + scm { + connection = "scm:git:https://github.com/plantbreeding/brapi-schema-tools" + developerConnection = "scm:git:ssh://github.com/plantbreeding/brapi-schema-tools.git" + url = "https://github.com/plantbreeding/brapi-schema-tools" + } + } + } +}