How to publish to Sonatype using publishSigned from sbt-pgp? - sbt

I want to publish a Scala library with sbt using sbt-pgp 0.8. I've registered groupId org.bitbucket.sergey_kozlov at Sonatype.
My build.sbt:
organization := "org.bitbucket.sergey_kozlov"
name := "playingcards"
version := "0.1-SNAPSHOT"
publishMavenStyle := true
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (isSnapshot.value)
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
publishArtifact in Test := false
pomIncludeRepository := { _ => false }
pomExtra :=
<url>https://bitbucket.org/sergey_kozlov/playingcards</url>
<licenses>
<license>
<name>The MIT License</name>
<url>http://www.opensource.org/licenses/mit-license.php</url>
<distribution>repo</distribution>
</license>
</licenses>
<scm>
<url>https://bitbucket.org/sergey_kozlov/playingcards.git</url>
<connection>scm:git:ssh://git#bitbucket.org/sergey_kozlov/playingcards.git</connection>
</scm>
<developers>
<developer>
<id>skozlov</id>
<name>Sergey Kozlov</name>
<email>mail.sergey.kozlov#gmail.com</email>
<roles>
<role>architect</role>
<role>developer</role>
</roles>
</developer>
</developers>
libraryDependencies += "junit" % "junit" % "4.11"
libraryDependencies += "org.scalatest" % "scalatest_2.10" % "2.0" % "test"
There's also ~/.sbt/0.13/plugins/gpg.sbt:
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8")
No other files are under project/ directory that contribute to the build definition.
When I enter publishSigned in sbt console, I get the following error:
[error] (*:publishSigned) java.io.IOException: Access to URL https://oss.sonatype.org/content/repositories/snapshots/playingcards/playingcards_2.10/0.1-SNAPSHOT/playingcards_2.10-0.1-SNAPSHOT-sources.jar was refused by the server: Forbidden
Note that the URL does not contain organization.
How can I publish my artifact correctly?

As you pointed out your URL is missing organization property this is why you get this error. Try to run show organization in sbt console to be sure that your organization property is correct. If it doesn't help try to specify your project explicitly in sbt and set organization property there.
lazy val core = (project in file(".")).settings(
organization := "org.bitbucket.sergey_kozlov"
//other properties here
)

Related

Build a Jar with and without provided dependencies

I have an SBT project, with spark dependencies. These dependencies are provided at runtime, and hence I import them under provided scope.
val hadoop = Seq("org.apache.hadoop" % "hadoop-client" % "3.3.1" % provided)
val spark = Seq(
"org.apache.spark" %% "spark-core" % SparkVersion % provided,
"org.apache.spark" %% "spark-sql" % SparkVersion % provided,
"org.apache.spark" %% "spark-mllib" % SparkVersion % provided
)
lazy val coreDto = (project in file("xxxx"))
.enablePlugins(BuildInfoPlugin)
.enablePlugins(PackPlugin)
.settings(
name := "xxxx",
moduleName := "xxxx",
version := "1.0",
libraryDependencies ++= (hadoop ++ spark))
All is well till now. Now I have a new scenario, where I have to publish the jar to our maven repository. And successfully I am able to publish it. The issue now is: provided scope. As the compile time dependencies are not appropriately set.
Question: How do I configure, where the provided scope is ignored during publishing? But still considered when I package it?
Using this to publish in case if helpful
lazy val publishSettings = Seq(
publishMavenStyle := true,
publishTo := {
val url = "https://xxxxl/maven/v1/"
if (version.value.trim.toUpperCase.endsWith("SNAPSHOT"))
Some("snapshots".at(url))
else
Some("releases".at(url))
},
aetherDeploy / logLevel := Level.Info,
aetherOldVersionMethod := true,
credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
)

sbt says "not a valid command" but plugin enabled

I have a plugin called sonar, which is developed and published as an AutoPlugin:
object Sonar extends AutoPlugin {
object autoImport {
lazy val sonar = taskKey[Unit]("sonar")
}
import autoImport._
override def trigger = allRequirements
lazy val sonarTask = Def.task {
<snip task code here which runs sonarqube scanner>
}
}
We then have a project which uses that plugin, with plugins.sbt that looks like this:
resolvers ++= Seq(
"Nexus Snapshot repo" at "url here"
)
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
addSbtPlugin("packagename" % "sonar" % "1.0-SNAPSHOT")
And build.sbt like this:
name := "hashing-library"
organization := "org name here"
scalaVersion := "2.12.6"
autoScalaLibrary := false
crossPaths := false
resolvers += "Nexus Release repo" at "https://nexusurl/content/repositories/releases/"
resolvers += "nexus Snapshot repo" at "https://nexusurl/content/repositories/snapshots/"
credentials += Credentials(Path.userHome / ".ivy2" / ".credentials")
// Publishing options:
publishMavenStyle := true
publishArtifact in Test := false
pomIncludeRepository := { x => false }
publishTo := {
val nexus = "nexus url here"
if (isSnapshot.value)
Some("sonatype-snapshots" at nexus + "content/repositories/snapshots")
else
Some("sonatype-releases" at nexus + "content/repositories/releases")
}
When I try to run sbt plugins, it says the plugin is enabled:
<snip output>
packagename.sonar.Sonar: enabled in hashingLibrary
So why is it that my plugin is enabled, but I cannot run sbt sonar? When I do, it says:
[info] Set current project to hashing-library (in build file:/home/work/hashing-library/)
[error] Not a valid command: sonar
[error] Not a valid project ID: sonar
[error] Expected ':'
[error] Not a valid key: sonar
[error] sonar
[error]
(Obviously org names and url's have been removed to protect confidentiality of my client, but hopefully that doesn't impact my question!)
The missing part of your plugin is the connection between the sonar task key and the sonarTask task implementation, i.e. you need to say somewhere that the key is set to the value of the implementation. You normally do it by overriding project settings in the plugin:
override def projectSettings = Seq(
sonar := sonarTask.value
)

sbt assembly not publishing fat jar

I can sbt assembly myself a fat jar without an issue with the below build.sbt file. However when I try to publish this "fat jar", sbt publish dumps only 1kb .jar files in the s3 bucket.
Unzipping the .jar file shows that it only contains a manifest file.
How do I get the fat jar into my repo?
update: striked text has been altered since initial question was posed. Removed the name override and it now publishes the build code but without the external libraries
below, my build.sbt file
name := "util_myutil"
version := "1.0.1"
scalaVersion := "2.10.4"
scalacOptions += "-target:jvm-1.7"
libraryDependencies += "org.apache.spark" % "spark-core_2.10" % "1.5.0-cdh5.5.2" % "provided"
unmanagedJars in Compile += file(".lib/my.jar")
unmanagedJars in Compile += file(".lib/some_other.jar")
assemblyOption in assembly := (assemblyOption in assembly).value.copy(includeScala = false)
assemblyJarName in assembly := s"${name.value}-${version.value}.jar"
ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
resolvers ++= Seq(
"Cloudera repos" at "https://repository.cloudera.com/artifactory/cloudera-repos",
"Cloudera releases" at "https://repository.cloudera.com/artifactory/libs-release",
"Era7 maven releases" at "https://s3-eu-west-1.amazonaws.com/releases.era7.com"
)
s3sse := true
s3region := com.amazonaws.services.s3.model.Region.US_Standard
s3acl := com.amazonaws.services.s3.model.CannedAccessControlList.Private
s3overwrite := true
publishMavenStyle := true
publishTo := {
val suffix = if (isSnapshot.value) "snapshots" else "releases"
Some(s3resolver.value(s"IT Insights Artifacts $suffix", s3("my-mvn-repo." + suffix)))
}
from https://github.com/sbt/sbt-assembly:
add this to your build.sbt:
artifact in (Compile, assembly) := {
val art = (artifact in (Compile, assembly)).value
art.copy(`classifier` = Some("assembly"))
}
addArtifact(artifact in (Compile, assembly), assembly)

Sign and publish debian package

I'm trying to build a debian package, sign it and publish it using the sbt-native-packager.
Is there example of how to sign debian package with GPG id ?
Here is what I did until now :
name := """play-scala-app-name"""
lazy val root = (project in file(".")).enablePlugins(PlayScala, DebianPlugin)
scalaVersion := "2.11.7"
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.0-RC1" % Test,
"org.mockito" % "mockito-core" % "1.10.19"
)
resolvers += "scalaz-bintray" at "https://dl.bintray.com/scalaz/releases"
name in Debian := "app-name"
version in Debian := "1.0"
maintainer in Debian := "maintainer name <maintainer#mail.com>"
packageSummary := "app summary"
packageDescription := """app description"""
publishTo := Some("Debian repo" at "https://repo")
credentials += Credentials("Debian repo Manager", "my.artifact.repo.net", "admin", "admin123")
// how to add code to sign the package ?
Then I will launch sbt clean debian:packageBin debian:publish ?
Native-packager provides a way to call the dpkg-sig command to a sign a package. This command should do the trick
sbt debianSign
You need dpkg-sig installed.

sbt modify the lib output directory when using sbt-native-packager

How can I modify the output of the final packaged zip to move the "lib" directory contents up one level. Basically I output a zip and the contents are like so:
ZIP FILE CONTENT:
-- my-plugin-1.0.jar
-- /lib
-- /lib/mydependency1.jar
-- /lib/mydependency2.jar
ZIP FILE CONTENT I WISH TO HAVE:
-- my-plugin-1.0.jar
-- mydependency1.jar
-- mydependency2.jar
I want to move everything in "lib" up one level to the root output.
sbt version 0.13.0
Here is my build.sbt:
import NativePackagerHelper._
organization := "com.company.product"
name := "my-plugin"
version := "1.0"
enablePlugins(UniversalPlugin)
packageName in Universal:= "deployment"
publishArtifact in (Compile, packageDoc) := false
artifactName := {
(sv: ScalaVersion, module: ModuleID, artifact: Artifact) =>
artifact.name + "-" + module.revision + "." + artifact.extension
}
javacOptions ++= Seq("-source", "1.8")
mappings in Universal <+= packageBin in Compile map { jar => jar -> (jar.getName()) }
topLevelDirectory := None
plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0")
command line:
sbt universal:packageBin
Looks like your requirement is a first class citizen in sbt-native-packager:
mappings in Universal ++= contentOf("src/main/resources/cache")

Resources