Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 107 lines (72 sloc) 5.834 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 := (
44 <licenses>
45 <license>
46 <name>BSD-style</name>
47 <url>http://www.opensource.org/licenses/bsd-license.php</url>
48 <distribution>repo</distribution>
49 </license>
50 </licenses>
51 <scm>
52 <url>git@github.com:jsuereth/scala-arm.git</url>
53 <connection>scm:git:git@github.com:jsuereth/scala-arm.git</connection>
54 </scm>
55 <developers>
56 <developer>
57 <id>jsuereth</id>
58 <name>Josh Suereth</name>
59 <url>http://jsuereth.com</url>
60 </developer>
61 </developers>)
62
63
64 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.
65
66 *The full format of a pom.xml file is [outlined here](http://maven.apache.org/pom.html).*
67
68 ## Fourth - Adding credentials ##
69
70 The credentails for your Sonatype OSSRH account need to be added somewhere. Common convention is a `~/.sbt/sonatype.sbt` file with the following:
71
72 credentials += Credentials("Sonatype Nexus Repository Manager", "oss.sonatype.org", "<your username>", "<your password>")
73
74 *Note: The first two strings **must** be `"Sonatype Nexus Repository Manager"` and `"oss.sonatype.org"` for Ivy to use the credentials.*
75
76 ## Finally - Publish ##
77
78 In SBT, run `publish` and you should see something like the following:
79
80 > publish
81 Please enter your PGP passphrase> ***********
82 [info] Packaging /home/josh/projects/typesafe/scala-arm/target/scala-2.9.1/scala-arm_2.9.1-1.2.jar ...
83 [info] Wrote /home/josh/projects/typesafe/scala-arm/target/scala-2.9.1/scala-arm_2.9.1-1.2.pom
84 [info] Packaging /home/josh/projects/typesafe/scala-arm/target/scala-2.9.1/scala-arm_2.9.1-1.2-javadoc.jar ...
85 [info] Packaging /home/josh/projects/typesafe/scala-arm/target/scala-2.9.1/scala-arm_2.9.1-1.2-sources.jar ...
86 [info] :: delivering :: com.jsuereth#scala-arm_2.9.1;1.2 :: 1.2 :: release :: Mon Jan 23 13:16:57 EST 2012
87 [info] Done packaging.
88 [info] Done packaging.
89 [info] Done packaging.
90 [info] delivering ivy file to /home/josh/projects/typesafe/scala-arm/target/scala-2.9.1/ivy-1.2.xml
91 [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
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-javadoc.jar.asc
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-sources.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.jar
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.asc
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.pom.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
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-javadoc.jar
99 [success] Total time: 9 s, completed Jan 23, 2012 1:17:03 PM
100
101
102
103 VIOILA! You're now publishing.
104
105
106
Something went wrong with that request. Please try again.