Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some more setup instructions to the README #108

Merged
merged 1 commit into from
Feb 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ####
szpak marked this conversation as resolved.
Show resolved Hide resolved

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