From 1a1688c862a10bd298299c7a260562348955cddd Mon Sep 17 00:00:00 2001 From: Nayan Hajratwala Date: Tue, 8 Jun 2021 10:08:06 -0400 Subject: [PATCH] Added some more setup instructions to the README --- README.md | 122 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 117 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 019a61c8..823aad9e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ The plugin must be applied to the root project and requires Gradle 5.0 or later. set the group and the version to the root project, so the plugin can detect if it is a snapshot version or not in order to select the correct repository where artifacts will be published. -```gradle +```groovy plugins { id("io.github.gradle-nexus.publish-plugin") version "«version»" } @@ -29,7 +29,7 @@ version = "1.0.0" In order to publish to Maven Central (aka the Central Repository or just Central) via Sonatype's OSSRH Nexus, you simply need to add the `sonatype()` repository like in the example below. Its `nexusUrl` and `snapshotRepositoryUrl` values are pre-configured. -```gradle +```groovy nexusPublishing { repositories { sonatype() @@ -39,7 +39,7 @@ nexusPublishing { **Important**. Users registered in Sonatype after [24 February 2021](https://central.sonatype.org/news/20210223_new-users-on-s01/) need to customize the following URLs: -```gradle +```groovy nexusPublishing { repositories { sonatype { //only for users registered in Sonatype after 24 Feb 2021 @@ -55,7 +55,7 @@ In addition, for both groups of users, you need to set your Nexus credentials. T Alternatively, you can configure credentials in the `sonatype` block: -```gradle +```groovy nexusPublishing { repositories { sonatype { @@ -66,6 +66,56 @@ nexusPublishing { } ``` +#### Configure Signing #### + +Add the signing plugin: +```kotlin +plugins { + // ... + signing +} +``` +then configure: +```kotlin +signing { + sign(publishing.publications["mavenJava"]) +} +``` +#### Add Metadata #### +```kotlin +publishing { + publications { + create("mavenJava") { + from(components["java"]) + + pom { + name.set("<>") + description.set("<>") + url.set("<>") + licenses { + license { + name.set("<>") + url.set("<>") + } + } + developers { + developer { + id.set("<>") + name.set("<>") + email.set("<>") + } + } + scm { + connection.set("<>") + developerConnection.set("<>") + url.set("<>") + } + } + } + } +} +``` + Finally, call `publishToSonatype closeAndReleaseSonatypeStagingRepository` to publish all publications to Sonatype's OSSRH Nexus and subsequently close and release the corresponding staging repository, effectively making the artifacts available in Maven Central (usually after a few minutes). Note that until [#19](https://github.com/gradle-nexus/publish-plugin/issues/19) is done, the `publishToSonatype closeAndReleaseSonatypeStagingRepository` tasks have to be executed in the same Gradle invocation because `closeAndRelease` relies on information that is not persisted between calls to Gradle. Failing to do so will result in an error like `No staging repository with name sonatype created`. @@ -76,10 +126,11 @@ Please bear in mind that - especially on the initial project publishing to Maven #### Groovy DSL -```gradle +```groovy plugins { id "java-library" id "maven-publish" + id "signing" id "io.github.gradle-nexus.publish-plugin" version "«version»" } @@ -88,6 +139,29 @@ publishing { mavenJava(MavenPublication) { from(components.java) } + pom { + name = "<>" + description = "<>" + url = "<>" + licenses { + license { + name = "<>" + url = "<>" + } + } + developers { + developer { + id = "<>" + name = "<>" + email = "<>" + } + } + scm { + connection = "<>" + developerConnection = "<>" + url = "<>" + } + } } } @@ -101,6 +175,10 @@ nexusPublishing { } } } + +signing { + sign publishing.publications.mavenJava +} ``` #### Kotlin DSL @@ -109,6 +187,7 @@ nexusPublishing { plugins { `java-library` `maven-publish` + signing id("io.github.gradle-nexus.publish-plugin") version "«version»" } @@ -117,6 +196,29 @@ publishing { create("mavenJava") { from(components["java"]) } + pom { + name.set("<>") + description.set("<>") + url.set("<>") + licenses { + license { + name.set("<>") + url.set("<>") + } + } + developers { + developer { + id.set("<>") + name.set("<>") + email.set("<>") + } + } + scm { + connection.set("<>") + developerConnection.set("<>") + url.set("<>") + } + } } } @@ -130,12 +232,22 @@ nexusPublishing { } } } + +signing { + sign(publishing.publications["mavenJava"]) +} ``` ### HTTP Timeouts You can configure the `connectTimeout` and `clientTimeout` properties on the `nexusPublishing` extension to set the connect and read/write timeouts (both default to 5 minutes). Good luck! +### Troubleshooting + +Log into your staging repository account. On the left side, expand "Build Promotion", then click "Staging Repositories". +Here, you should see your newly created repositories. You can click on one of them, then select the "Activity" tab to +see any errors that have occurred. + --- ## Behind the scenes