Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.marcphilipp:nexus-publish-plugin:0.4.0'
}
dependencies {
implementation("com.github.marcphilipp:nexus-publish-plugin:0.4.0")
}
<dependency>
<groupId>com.github.marcphilipp</groupId>
<artifactId>nexus-publish-plugin</artifactId>
<version>0.4.0</version>
</dependency>
libraryDependencies += "com.github.marcphilipp" % "nexus-publish-plugin" % "0.4.0"
:dependencies [[com.github.marcphilipp/nexus-publish-plugin "0.4.0"]]
Gradle Plugin that explicitly creates a Staging Repository before publishing to Nexus. This solves the problem that frequently occurs when uploading to Nexus from Travis, namely split staging repositories.
This plugin is now deprecated and no longer maintained. The Gradle Nexus Publish Plugin is the successor of this plugin and adds additional tasks to close and release staging repositories.
The plugin does the following:
maven-publish
pluginnexusPublishing { repositories { ... } }
blockinitialize${repository.name.capitalize()}StagingRepository
task that starts a new staging repository in case the project's version does not end with -SNAPSHOT
(customizable via the useStaging
property) and sets the URL of the corresponding Maven artifact repository accordingly. In case of a multi-project build, all subprojects with the same nexusUrl
will use the same staging repository.io.codearte.nexus-staging
plugin is applied on the root project, the stagingRepositoryId
on its extension is set to the id of the newly created staging repository, this way it does not depend on exactly one open staging repository being available.initialize${repository.name.capitalize()}StagingRepository
task.publishTo${repository.name.capitalize()}
lifecycle task that depends on all publishing tasks for the corresponding Maven artifact repository.In order to publish to Maven Central via Sonatype's OSSRH Nexus, you simply need to add the sonatype()
repository like in the example below. It's nexusUrl
and snapshotRepositoryUrl
are pre-configured.
nexusPublishing {
repositories {
sonatype()
}
}
In addition, you need to set the sonatypeUsername
and sonatypePassword
project properties, e.g. in ~/.gradle/gradle.properties
. Alternatively, you can configure username and password in the sonatype
block:
nexusPublishing {
repositories {
sonatype {
username = "your-username"
password = "your-password"
}
}
}
Finally, call publishToSonatype
to publish all publications to Sonatype's OSSRH Nexus.
plugins {
id "java-library"
id "de.marcphilipp.nexus-publish" version "0.3.0"
}
publishing {
publications {
mavenJava(MavenPublication) {
from(components.java)
}
}
}
nexusPublishing {
repositories {
myNexus {
nexusUrl = uri("https://your-server.com/staging")
snapshotRepositoryUrl = uri("https://your-server.com/snapshots")
username = "your-username" // defaults to project.properties["myNexusUsername"]
password = "your-password" // defaults to project.properties["myNexusPassword"]
}
}
}
plugins {
`java-library`
id("de.marcphilipp.nexus-publish") version "0.3.0"
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
from(components["java"])
}
}
}
nexusPublishing {
repositories {
create("myNexus") {
nexusUrl.set(uri("https://your-server.com/staging"))
snapshotRepositoryUrl.set(uri("https://your-server.com/snapshots"))
username.set("your-username") // defaults to project.properties["myNexusUsername"]
password.set("your-password") // defaults to project.properties["myNexusPassword"]
}
}
}
If the io.codearte.nexus-staging
plugin is applied on the root project, the following default values change:
| Property | Default value |
| ------------------- | -------------------------------------------- |
| packageGroup
| rootProject.nexusStaging.packageGroup
|
| stagingProfileId
| rootProject.nexusStaging.stagingProfileId
|
| username
| rootProject.nexusStaging.username
|
| password
| rootProject.nexusStaging.password
|
This reuses the values specified for the nexusStaging
block, so you don't have to specify them twice.
You can configure the connectTimeout
and clientTimeout
properties on the nexusPublishing
extension to set the connect and read/write timeouts (both default to 1 minute). Good luck!