We had some custom code in build.sbt to publish debian binaries to nexus for sbt 0.13
lazy val distrib = com.typesafe.sbt.packager.Keys.dist
publish := (publish) dependsOn distrib
publishLocal := (publishLocal) dependsOn distrib
artifact in distHack ~= { (art: Artifact) => art.copy(`type` = "deb", extension = "deb") }
val distHack = TaskKey[File]("dist-hack", "Hack to publish dist")
val distHackSettings = Seq[Setting[_]](
distHack := {
val packageName = "%s_%s_all" format(normalizedName.value, version.value)
target.value / (packageName + ".deb")
}
) ++ Seq(addArtifact(artifact in distHack, distHack).settings: _*)
seq(distHackSettings: _*)
//addArtifact(artifact in distHack, distHack)
publishArtifact in (Compile, packageBin) := false
publishArtifact in (Compile, packageDoc) := false
publishArtifact in (Compile, packageSrc) := false
But, it does not work under sbt 1.x.
Does anybody have any pointers to proceed?
Note: I have read through all the related questions on stackoverflow already.
I found the solution. You use the following code
lazy val distrib = com.typesafe.sbt.packager.Keys.dist
artifact in (Compile, packageBin) := {
val previous: Artifact = (artifact in (Compile, packageBin)).value
previous.withExtension("deb")
}
publish := (publish dependsOn distrib).value
publishLocal := (publishLocal dependsOn distrib).value
publishArtifact in (Compile, packageBin) := true
publishArtifact in (Compile, packageDoc) := false
publishArtifact in (Compile, packageSrc) := false
publishArtifact in Test := false
Related
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")
)
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)
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
)
I have the next configuration:
lazy val mainProject = Project(
id = "project-helper",
base = file("."),
settings = Project.defaultSettings ++ Seq(
name := "my-first-project",
version := "0.1-SNAPSHOT",
scalaVersion := "2.10.2",
licenses += ("MIT", url("http://opensource.org/licenses/MIT")),
publishMavenStyle := false,
pomExtra := pomXml,
publishArtifact in Test := false,
resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases",
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % "2.10.3",
"org.scalamacros" % "quasiquotes_2.10.3" % "2.0.0-M3"
),
addCompilerPlugin("org.scalamacros" % "paradise" % "2.0.0-M3" cross CrossVersion.full)
)
)
I want publish this into a bintray.
I do publish but i got error:
java.lang.RuntimeException: Repository for publishing is not specified.
at scala.sys.package$.error(package.scala:27)
at sbt.Classpaths$$anonfun$getPublishTo$1.apply(Defaults.scala:1203)
at sbt.Classpaths$$anonfun$getPublishTo$1.apply(Defaults.scala:1203)
at scala.Option.getOrElse(Option.scala:120)
I use a bintray-sbt plugin.
Thanks
See the README:
Publishing
To publish a package to bintray, you need a bintray account. You can do so here. After creating a bintray account you can add
seq(bintrayPublishSettings:_*)
You likely need something like this.
import bintray.Plugin._
lazy val mainProject = Project(id = "project-helper", base = file(".")).
settings(bintrayPublishSettings: _*).
settings(
name := "my-first-project",
version := "0.1-SNAPSHOT",
scalaVersion := "2.10.2",
licenses += ("MIT", url("http://opensource.org/licenses/MIT")),
publishMavenStyle := false,
pomExtra := pomXml,
publishArtifact in Test := false,
resolvers += "Typesafe Releases" at "http://repo.typesafe.com/typesafe/releases",
libraryDependencies ++= Seq(
"org.scala-lang" % "scala-reflect" % "2.10.3",
"org.scalamacros" % "quasiquotes_2.10.3" % "2.0.0-M3"
),
addCompilerPlugin("org.scalamacros" % "paradise" % "2.0.0-M3" cross CrossVersion.full)
)
Same way (but different) could be to just append to settings:
++ bintray.Plugin.bintraySettings
Adding the following settings to the build.sbt file of a Play 2.2.x app
does not disable Scaladoc generation. How can it be disabled?
play.Project(appName, appVersion, appDependencies)
.settings(scalaVersion := "2.10.3")
.settings(jsSettings : _*)
.settings(
publishArtifact in (Compile, packageDoc) := false,
publishArtifact in packageDoc := false
)
Add the following settings to the Play project:
sources in (Compile,doc) := Seq.empty
publishArtifact in (Compile, packageDoc) := false
With the change it should be as follows:
play.Project(appName, appVersion, appDependencies)
.settings(scalaVersion := "2.10.3")
.settings(jsSettings : _*)
.settings(
publishArtifact in (Compile, packageDoc) := false,
publishArtifact in packageDoc := false,
sources in (Compile,doc) := Seq.empty
)
Thanks #peter-hilton for the comment!