Skip to content

Commit

Permalink
Added some more setup instructions to the README
Browse files Browse the repository at this point in the history
  • Loading branch information
nhajratw committed Jun 8, 2021
1 parent d3786fa commit 1a1688c
Showing 1 changed file with 117 additions and 5 deletions.
122 changes: 117 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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»"
}
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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<MavenPublication>("mavenJava") {
from(components["java"])

pom {
name.set("<<Component Name>>")
description.set("<<Component Description>>")
url.set("<<Component URL>>")
licenses {
license {
name.set("<<License Name>>")
url.set("<<License URL>>")
}
}
developers {
developer {
id.set("<<Developer ID>>")
name.set("<<Developer Name>>")
email.set("<<Developer Email>>")
}
}
scm {
connection.set("<<SCM Connection URL>>")
developerConnection.set("<<SCM Dev Connection URL>>")
url.set("<<Source URL>>")
}
}
}
}
}
```

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`.
Expand All @@ -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»"
}
Expand All @@ -88,6 +139,29 @@ publishing {
mavenJava(MavenPublication) {
from(components.java)
}
pom {
name = "<<Component Name>>"
description = "<<Component Description>>"
url = "<<Component URL>>"
licenses {
license {
name = "<<License Name>>"
url = "<<License URL>>"
}
}
developers {
developer {
id = "<<Developer ID>>"
name = "<<Developer Name>>"
email = "<<Developer Email>>"
}
}
scm {
connection = "<<SCM Connection URL>>"
developerConnection = "<<SCM Dev Connection URL>>"
url = "<<Source URL>>"
}
}
}
}
Expand All @@ -101,6 +175,10 @@ nexusPublishing {
}
}
}
signing {
sign publishing.publications.mavenJava
}
```

#### Kotlin DSL
Expand All @@ -109,6 +187,7 @@ nexusPublishing {
plugins {
`java-library`
`maven-publish`
signing
id("io.github.gradle-nexus.publish-plugin") version "«version»"
}

Expand All @@ -117,6 +196,29 @@ publishing {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
pom {
name.set("<<Component Name>>")
description.set("<<Component Description>>")
url.set("<<Component URL>>")
licenses {
license {
name.set("<<License Name>>")
url.set("<<License URL>>")
}
}
developers {
developer {
id.set("<<Developer ID>>")
name.set("<<Developer Name>>")
email.set("<<Developer Email>>")
}
}
scm {
connection.set("<<SCM Connection URL>>")
developerConnection.set("<<SCM Dev Connection URL>>")
url.set("<<Source URL>>")
}
}
}
}

Expand All @@ -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
Expand Down

0 comments on commit 1a1688c

Please sign in to comment.