在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):gradle-nexus/publish-plugin开源软件地址(OpenSource Url):https://github.com/gradle-nexus/publish-plugin开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):Gradle Nexus Publish PluginThis Gradle plugin is a turn-key solution for publishing to Nexus. You can use it to publish your artifacts to any Nexus instance (internal or public). It is great for publishing your open source to Sonatype, and then to Maven Central, in a fully automated fashion. Vanilla Gradle is great but it cannot fully automate publications to Nexus. This plugin enables isolation of staging repositories so that you can reliably publish from CI, and each publication uses a brand new, explicitly created staging repo (more). Moreover, the plugin provides tasks to close and release staging repositories, covering the whole releasing process to Maven Central. This plugin is intended as a replacement of the Gradle Nexus Staging Plugin and Nexus Publish Plugin duo. See a dedicated migration guide. UsageApplying the pluginThe plugin must be applied to the root project and requires Gradle 5.0 or later. It is important to 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. plugins {
id("io.github.gradle-nexus.publish-plugin") version "«version»"
}
group = "com.example.library"
version = "1.0.0" Publishing to Maven Central via Sonatype OSSRHIn order to publish to Maven Central (aka the Central Repository or just Central) via Sonatype's OSSRH Nexus, you simply need to add the nexusPublishing {
repositories {
sonatype()
}
} Important. Users registered in Sonatype after 24 February 2021 need to customize the following URLs: nexusPublishing {
repositories {
sonatype { //only for users registered in Sonatype after 24 Feb 2021
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
} (if unsure check the server address in a corresponding ticket for your project in Sonatype's Jira) In addition, for both groups of users, you need to set your Nexus credentials. To increase security, it is advised to use the user token's username and password pair (instead of regular username and password). Those values should be set as the Alternatively, you can configure credentials in the nexusPublishing {
repositories {
sonatype {
username = "your-user-token-username"
password = "your-user-token-password"
}
}
} Finally, call Note that until #19 is done, the Please bear in mind that - especially on the initial project publishing to Maven Central - it might be wise to call just Full exampleGroovy DSLplugins {
id "java-library"
id "maven-publish"
id "io.github.gradle-nexus.publish-plugin" version "«version»"
}
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"]
}
}
} Kotlin DSLplugins {
`java-library`
`maven-publish`
id("io.github.gradle-nexus.publish-plugin") version "«version»"
}
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"]
}
}
} HTTP TimeoutsYou can configure the Retries for state transitionsWhen closing or releasing a staging repository the plugin first initiates the transition and then retries a configurable number of times with a configurable delay after each attempt. Both can be configured like this: Groovy DSLimport java.time.Duration
nexusPublishing {
transitionCheckOptions {
maxRetries = 100
delayBetween = Duration.ofSeconds(5)
}
} Kotlin DSLimport java.time.Duration
nexusPublishing {
transitionCheckOptions {
maxRetries.set(100)
delayBetween.set(Duration.ofSeconds(5))
}
}
Behind the scenesThe plugin does the following:
Historical backgroundIn 2015, Marcin Zajączkowski created gradle-nexus-staging-plugin which was providing an ability to close and release staging repositories in Nexus repository manager. It opened an opportunity to manage releasing Gradle projects to Maven Central completely from code. Over the years, it has been adopted by various projects across the globe, however there was a small problem. Due to technical limitations in the publishing process in Gradle, it was required to use heuristics to track implicitly created staging repositories, what often failed for multiple repositories in a given state. The situation became even worse when Travis changed its network architecture in late 2019 and the majority of releases started to fail. Here, Marc Philipp entered the stage who created Nexus Publish Plugin which was enriching the publishing mechanism in Gradle to explicitly create staging repositories and publish (upload) artifacts directly to it. Those two plugins nicely worked together, providing a reliable way to handle publishing artifacts to Maven Central (and to other Nexus instances in general). However, the need of using two plugins was very often confusing for users. As a result, an idea to create one plugin mixing the aforementioned capabilities emerged. It materialized in 2020/2021 as Gradle Nexus Publish Plugin, an effect of combined work of Marc and Marcin, supported by a pack of contributors. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论