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

sbt-sonatype-3.0 #87

Merged
merged 19 commits into from
Sep 5, 2019
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
maxColumn = 180
version = 2.0.1
maxColumn = 120
style = defaultWithAlign
optIn.breaksInsideChains = true
112 changes: 66 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
sbt-sonatype plugin
======

A sbt plugin for publishing your project to the Maven central repository through the REST API of Sonatype Nexus. Deploying artifacts to Sonatype repository is a requirement for synchronizing your projects to the [Maven central repository](http://repo1.maven.org/maven2/). __sbt-sonatype__ plugin enables two-step release of Scala/Java projects.
A sbt plugin for publishing your project to the Maven central repository through the REST API of Sonatype Nexus. Deploying artifacts to Sonatype repository is a requirement for synchronizing your projects to the [Maven central repository](http://repo1.maven.org/maven2/). __sbt-sonatype__ plugin enables three-step release of Scala/Java projects.

* `sonatypePrepare`
* Prepare a staging repository at Sonatype. It will also clean up previously created staging repositories. This step is added since sbt-sonatype 3.0 to resume the entire release process from scratch.
* `publishSigned` (with [sbt-pgp plugin](http://www.scala-sbt.org/sbt-pgp/))
* Upload GPG signed artifacts to Sonatype repository
* `sonatypeRelease`
* Perform the close and release steps in the Sonatype Nexus repository.

After these steps, your project will be synchronized to the Maven central (usually) within ten minutes. No longer need to enter the web interface of
[Sonatype Nexus repository](http://oss.sonatype.org/) to performe these release steps.

* First `publishSigned` (with [sbt-pgp plugin](http://www.scala-sbt.org/sbt-pgp/))
* Next `sonatypeRelease` to perform the close and release steps in the Sonatype Nexus repository.
* Done. Your project will be synchronized to the Maven central within tens of minutes. No longer need to enter the web interface of
[Sonatype Nexus repository](http://oss.sonatype.org/).

- [Release notes](ReleaseNotes.md)
- sbt-sonatype is available for sbt-0.13.5 or later.
- sbt-sonatype is available for sbt 1.x series.
- You can also use sbt-sonatype for [publishing non-sbt projects](README.md#publishing-maven-projects) (e.g., Maven, Gradle, etc.)


## Prerequisites

* Create a Sonatype Repository account
* Follow the instruction in the [Central Repository documentation site](http://central.sonatype.org).
* Follow the instruction in the [Central Repository documentation site](http://central.sonatype.org).
* Create a Sonatype account
* Create a GPG key
* Open a JIRA ticket to get a permission for synchronizing your project to the Central Repository (aka Maven Central).
Expand All @@ -35,22 +40,25 @@ A sbt plugin for publishing your project to the Maven central repository through
Import ***sbt-sonatype*** plugin and [sbt-pgp plugin](http://www.scala-sbt.org/sbt-pgp/) to use `sonatypeRelease` and `publishSigned`
commands:
```scala
// For sbt 0.13.x (upto sbt-sonatype 2.3)
// For sbt 1.x (sbt-sonatype 2.3 or higher)
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "(version)")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0-M2")

// For sbt 1.2.x (sbt-sonatype 2.3 or higher)
// For sbt 0.13.x (upto sbt-sonatype 2.3)
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "(version)")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.0")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
```

* If downloading the sbt-sonatype plugin fails, check the repository in the Maven central: <http://repo1.maven.org/maven2/org/xerial/sbt/sbt-sonatype_2.12_1.0>. It will be usually synced within 10 minutes.

### build.sbt

```scala
// Add the default sonatype repository setting
// [Important] Use publishTo settings set by sbt-sonatype plugin
publishTo := sonatypePublishTo.value

// [Optional] If you need to manage unique session names, change this setting:
sonatypeSessionName := s"[sbt-sonatype] ${name.value} ${version.value}",
```

### $HOME/.sbt/(sbt-version 0.13 or 1.0)/sonatype.sbt
Expand Down Expand Up @@ -129,45 +137,56 @@ $ sbt sonatypeRelease
```
This command accesses [Sonatype Nexus REST API](https://oss.sonatype.org/nexus-staging-plugin/default/docs/index.html), then sends close and promote commands.

## Available Commands

* __sonatypeList__
* Show the list of staging repositories.
* __sonatypeOpen__ (description | sonatypeProfileName description) (since sbt-sonatype-1.1)
* Create a staging repository and set `sonatypeStagingRepositoryProfile` and `publishTo`.
* Although creating a staging repository does not result in email notifications,
the description will be reused for across lifecycle operations (Close, Promote, Drop)
to facilitate distinguishing email notifications sent by the repository by description.
* __sonatypeClose__ (repositoryId)?
* Close an open staging repository and set `sonatypeStagingRepositoryProfile` and
clear `publishTo` if it was set by __sonatypeOpen__.
* The `Staging Completed` email notification sent by the repository only includes the description
(if created with __sonatypeOpen__); it does not include the staging repository ID.
* __sonatypePromote__ (repositoryId)?
* Promote a closed staging repository and set `sonatypeStagingRepositoryProfile` and
clear `publishTo` if it was set by __sonatypeOpen__.
* The `Promotion Completed` email notification sent by the repository only includes the description
(if created with __sonatypeOpen__); it does not include the staging repository ID.
* __sonatypeDrop__ (repositoryId)?
* Drop an open or closed staging repository and set `sonatypeStagingRepositoryProfile` and
clear `publishTo` if it was set by __sonatypeOpen__.
* The email notification sent by the repository includes both the description
(if created with __sonatypeOpen__) and the staging repository ID.
* __sonatypeDropAll__
* Drop all staging repositories.
## Commands

### Basic Commands
* __sonatypePrepare__
* Drop (if exists) and create a new staging repository using `sonatypeSessionName` as a unique key
* For cross-build projects, make sure running this command only once at the beginning of the release process. Then run `sonatypeOpen` for each build to reuse the already created stging repository.
* __sonatypeOpen__
* Open the existing staging repository using `sonatypeSessionName` as a unique key. If it doesn't exist, create a new one. It will update`sonatypePublishTo`
* This command is useful to run `publishSigned` task in parallel.
* __sonatypeRelease__ (repositoryId)?
* Close (if needed) and promote a staging repository and set `sonatypeStagingRepositoryProfile` and
clear `publishTo` if it was set by __sonatypeOpen__.
* The email notifications are those of __sonatypeClose__ (if applicable) and __sonatypePromote__.
* Close (if needed) and promote a staging repository. After this command, the uploaded artifacts will be synchronized to Maven central.

### Batch Operations
* __sonatypeDropAll__ (sonatypeProfileName)?
* Drop all staging repositories.
* __sonatypeReleaseAll__ (sonatypeProfileName)?
* Close and promote all staging repositories (Useful for cross-building projects)

## Others
* __sonatypeStagingProfiles__
* Show the list of staging profiles, which include profileName information.
* __sonatypeLog__
* Show the staging activity logs

### Advanced Usage

* __sonatypeClose__
* Close the open staging repository (= requirement verification)
* __sonatypePromote__
* Promote the closed staging repository (= sync to Maven central)
* __sonatypeDrop__
* Drop an open or closed staging repository

## Uploading Artifacts In Parallel

Since sbt-sonatype 3.x, it supports session based release flows:

### Single Module Projects
- sonatypePrepare
- publishSigned
- sonatypeRelease

### Multi Module Projects
- Run `sonatypePrepare` in a single step.
- You must wait for the completion of this step
- Then, start uploading signed artifacts using multiple processes:
- P1: `; sonatypeOpen; publishSigned`
- P2: `; sonatypeOpen; publishSigned`
- P3: ...
- Wait for all upload completion
- Finally, run `sonatypeRelease`

For sbt-sonatype 2.x:
* [Example workflow for creating & publishing to a staging repository](workflow.md)

## Using with sbt-release plugin
Expand All @@ -186,11 +205,12 @@ releaseProcess := Seq[ReleaseStep](
setReleaseVersion,
commitReleaseVersion,
tagRelease,
releaseStepCommand("sonatypePrepare"),
// For non cross-build projects, use releaseStepCommand("publishSigned")
releaseStepCommandAndRemaining("+publishSigned"),
releaseStepCommand("sonatypeRelease"),
setNextVersion,
commitNextVersion,
releaseStepCommand("sonatypeReleaseAll"),
pushChanges
)
```
Expand Down
32 changes: 17 additions & 15 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import ReleaseTransformations._

lazy val buildSettings = Seq(
lazy val buildSettings: Seq[Setting[_]] = Seq(
organization := "org.xerial.sbt",
organizationName := "Xerial project",
organizationHomepage := Some(new URL("http://xerial.org/")),
Expand All @@ -29,8 +29,8 @@ lazy val buildSettings = Seq(
scriptedLaunchOpts := {
scriptedLaunchOpts.value ++ Seq("-Xmx1024M", "-XX:MaxPermSize=256M", "-Dplugin.version=" + version.value)
},
crossSbtVersions := Vector("1.2.7"),
releaseCrossBuild := true,
crossSbtVersions := Vector("1.3.0"),
releaseCrossBuild := false,
releaseTagName := { (version in ThisBuild).value },
releasePublishArtifactsAction := PgpKeys.publishSigned.value,
releaseProcess := Seq[ReleaseStep](
Expand All @@ -41,23 +41,25 @@ lazy val buildSettings = Seq(
setReleaseVersion,
commitReleaseVersion,
tagRelease,
releaseStepCommandAndRemaining("^ publishSigned"),
releaseStepCommand("sonatypePrepare"),
releaseStepCommandAndRemaining("publishSigned"),
releaseStepCommand("sonatypeRelease"),
setNextVersion,
commitNextVersion,
releaseStepCommand("sonatypeReleaseAll"),
pushChanges
)
)

// Project modules
lazy val sbtSonatype = Project(
id = "sbt-sonatype",
base = file(".")
).enablePlugins(ScriptedPlugin)
.settings(buildSettings)
.settings(
libraryDependencies ++= Seq(
"org.apache.httpcomponents" % "httpclient" % "4.2.6",
"org.scalatest" %% "scalatest" % "3.0.1" % "test"
lazy val sbtSonatype =
project
.withId("sbt-sonatype")
.in(file("."))
.enablePlugins(ScriptedPlugin)
.settings(
buildSettings,
testFrameworks += new TestFramework("wvlet.airspec.Framework"),
libraryDependencies ++= Seq(
"org.apache.httpcomponents" % "httpclient" % "4.2.6"
)
)
)
3 changes: 1 addition & 2 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
sbt.version=1.2.7

sbt.version=1.3.0
7 changes: 3 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.7")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "2.3")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.1")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.1.0-M7")
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.0-SNAPSHOT")
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0-M2")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.3")

libraryDependencies += "org.scala-sbt" %% "scripted-plugin" % sbtVersion.value

Expand Down
Loading