Skip to content

Commit

Permalink
Merge branch 'pr/108'
Browse files Browse the repository at this point in the history
  • Loading branch information
szpak committed Feb 11, 2023
2 parents e9dde33 + 9615ba9 commit ab77ce3
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](https://docs.gradle.org/current/userguide/signing_plugin.html#sec:signing_publications) ####

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,6 +232,10 @@ nexusPublishing {
}
}
}

signing {
sign(publishing.publications["mavenJava"])
}
```

### HTTP Timeouts
Expand Down Expand Up @@ -170,6 +276,12 @@ nexusPublishing {
- `maxRetries` default value is 60.
- `delayBetween` default value is 10 seconds.

### 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 ab77ce3

Please sign in to comment.