Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 110 lines (74 sloc) 6.31 kb
55dc73b @jsuereth Creating help documentation for publishing to Sonatype's OSSRH
jsuereth authored
1 ---
2 layout: content
3 title: Deploying to Sonatype
4 ---
5
6 Deploying to sonatype is easy! Just follow these simple steps:
7
8 ## First - PGP Signatures ##
9
10 You'll need to PGP sign your artifacts for the Sonatype repository. Don't worry, there's a [plugin for that](http://scala-sbt.org/xsbt-gpg-plugin). Follow the instructions for the plugin and you'll have PGP signed artifacts in no time.
11
12 *Note: The plugin is a jvm-only solution to generate PGP keys and sign artifacts. It can work with the GPG command line tool, but the command line is not needed.*
13
14
15 ## Second - Maven Publishing Settings ##
16
17 To publish to a maven repository, you'll need to configure a few settings so that the correct metadata is generated.
18
19 publishMavenStyle := true
20
21 is used to ensure POMs are generated and pushed. Next, you have to set up the repositories you wish to push too. Luckily, Sonatype's OSSRH uses the same URLs for everyone:
22
23 publishTo <<= version { (v: String) =>
24 val nexus = "https://oss.sonatype.org/"
25 if (v.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
26 else Some("releases" at nexus + "service/local/staging/deploy/maven2")
27 }
28
29 Another good idea is to not publish your test artifacts:
30
31 publishArtifact in Test := false
32
33 ## Third - POM Metadata ##
34
35 Now, we want to control what's available in the `pom.xml` file. This file describes our project in the maven repository and is used by indexing services for search and discover. This means it's important that `pom.xml` should have all information we wish to advertise as well as required info!
36
37 First, let's make sure no repositories show up in the POM file. To publish on maven-central, all *required* artifacts must also be hosted on maven central. However, sometimes we have optional dependencies for special features. If that's the case, let's remove the repositories for optional dependencies in our artifact:
38
39 pomIncludeRepository := { x => false },
40
41 Next, the POM metadata that isn't generated by SBT must be added. This is done through the `pomExtra` configuration option:
42
43 pomExtra := (
c0c4dcb @jsuereth Adding missing docs.
jsuereth authored
44 <url>http://jsuereth.com/scala-arm</url>
55dc73b @jsuereth Creating help documentation for publishing to Sonatype's OSSRH
jsuereth authored
45 <licenses>
46 <license>
47 <name>BSD-style</name>
48 <url>http://www.opensource.org/licenses/bsd-license.php</url>
49 <distribution>repo</distribution>
50 </license>
51 </licenses>
52 <scm>
53 <url>git@github.com:jsuereth/scala-arm.git</url>
54 <connection>scm:git:git@github.com:jsuereth/scala-arm.git</connection>
55 </scm>
56 <developers>
57 <developer>
58 <id>jsuereth</id>
59 <name>Josh Suereth</name>
60 <url>http://jsuereth.com</url>
61 </developer>
62 </developers>)
63
64
65 Specifically, the `license`, `scm.url`, `scm.connection` and `developer` sections are required. The above is an example from the [scala-arm](http://jsuereth.com/scala-arm) project.
66
67 *The full format of a pom.xml file is [outlined here](http://maven.apache.org/pom.html).*
68
69 ## Fourth - Adding credentials ##
70
71 The credentails for your Sonatype OSSRH account need to be added somewhere. Common convention is a `~/.sbt/sonatype.sbt` file with the following:
72
73 credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", "<your username>", "<your password>")
74
75 *Note: The first two strings **must** be `"Sonatype Nexus Repository Manager"` and `"oss.sonatype.org"` for Ivy to use the credentials.*
76
77 ## Finally - Publish ##
78
79 In SBT, run `publish` and you should see something like the following:
80
81 > publish
82 Please enter your PGP passphrase> ***********
83 [info] Packaging /home/josh/projects/typesafe/scala-arm/target/scala-2.9.1/scala-arm_2.9.1-1.2.jar ...
84 [info] Wrote /home/josh/projects/typesafe/scala-arm/target/scala-2.9.1/scala-arm_2.9.1-1.2.pom
85 [info] Packaging /home/josh/projects/typesafe/scala-arm/target/scala-2.9.1/scala-arm_2.9.1-1.2-javadoc.jar ...
86 [info] Packaging /home/josh/projects/typesafe/scala-arm/target/scala-2.9.1/scala-arm_2.9.1-1.2-sources.jar ...
87 [info] :: delivering :: com.jsuereth#scala-arm_2.9.1;1.2 :: 1.2 :: release :: Mon Jan 23 13:16:57 EST 2012
88 [info] Done packaging.
89 [info] Done packaging.
90 [info] Done packaging.
91 [info] delivering ivy file to /home/josh/projects/typesafe/scala-arm/target/scala-2.9.1/ivy-1.2.xml
92 [info] published scala-arm_2.9.1 to https://oss.sonatype.org/service/local/staging/deploy/maven2/com/jsuereth/scala-arm_2.9.1/1.2/scala-arm_2.9.1-1.2-sources.jar
93 [info] published scala-arm_2.9.1 to https://oss.sonatype.org/service/local/staging/deploy/maven2/com/jsuereth/scala-arm_2.9.1/1.2/scala-arm_2.9.1-1.2-javadoc.jar.asc
94 [info] published scala-arm_2.9.1 to https://oss.sonatype.org/service/local/staging/deploy/maven2/com/jsuereth/scala-arm_2.9.1/1.2/scala-arm_2.9.1-1.2-sources.jar.asc
95 [info] published scala-arm_2.9.1 to https://oss.sonatype.org/service/local/staging/deploy/maven2/com/jsuereth/scala-arm_2.9.1/1.2/scala-arm_2.9.1-1.2.jar
96 [info] published scala-arm_2.9.1 to https://oss.sonatype.org/service/local/staging/deploy/maven2/com/jsuereth/scala-arm_2.9.1/1.2/scala-arm_2.9.1-1.2.jar.asc
97 [info] published scala-arm_2.9.1 to https://oss.sonatype.org/service/local/staging/deploy/maven2/com/jsuereth/scala-arm_2.9.1/1.2/scala-arm_2.9.1-1.2.pom.asc
98 [info] published scala-arm_2.9.1 to https://oss.sonatype.org/service/local/staging/deploy/maven2/com/jsuereth/scala-arm_2.9.1/1.2/scala-arm_2.9.1-1.2.pom
99 [info] published scala-arm_2.9.1 to https://oss.sonatype.org/service/local/staging/deploy/maven2/com/jsuereth/scala-arm_2.9.1/1.2/scala-arm_2.9.1-1.2-javadoc.jar
100 [success] Total time: 9 s, completed Jan 23, 2012 1:17:03 PM
101
102
103
c0c4dcb @jsuereth Adding missing docs.
jsuereth authored
104 After publishing you have to follow the [Release workflow of nexus](https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide#SonatypeOSSMavenRepositoryUsageGuide-8.ReleaseIt). In the future, we hope to provide a Nexus SBT plugin that allows the release workflow procedures to be performed directly from SBT.
105
106 *Note: Staged releases allow testing across large projects of independent releases before pushing the full project.*
55dc73b @jsuereth Creating help documentation for publishing to Sonatype's OSSRH
jsuereth authored
107
108
109
Something went wrong with that request. Please try again.