sbt-native-packager and RPM - how do I set required parameters? - scala

I'm finding it diffuclt to build a Play project using the sbt native packager. I don't know where to set the RPM configuration when I am given the following error:
[error] `rpmVendor in Rpm` is empty. Please provide a valid vendor for the rpm SPEC.
[error] `packageSummary in Rpm` is empty. Please provide a valid summary for the rpm SPEC.
[error] `packageDescription in Rpm` is empty. Please provide a valid description for the rpm SPEC.
I've set the following in project/plugins.sbt:
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "0.8.0")
In my build.sbt:
name := """supersecretproject"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
ws
)
libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.27"
javacOptions ++= Seq("-source", "1.6", "-target", "1.6")
tomcat()
The documentation merely states:
A rpm package needs some mandatory settings to be valid. Make sure you have these settings in your build:
rpmRelease := "1"
rpmVendor := "typesafe"
rpmUrl := Some("http://github.com/paulp/sbt-extras")
rpmLicense := Some("BSD")
Which is almost entirely useless if you don't know SBT very well! How do I "have these settings in your build:" as the documentation instructs?
I've tried adding the above "settings" to build.sbt or a separate packageSettings.sbt but with no luck as I just get the following error:
error: not found: value rpmRelease
rpmRelease := "1"
^
[error] Type error in expression
Note: I run the sbt using sbt rpm:packageBin

It sounds like the developers of that plugin are trying to not be too prescriptive, but in doing so have not given you enough information to even get started! :-(
The simplest possible solution: Copy those four settings (including the blank lines between) into your build.sbt.
A logical place is probably towards the bottom of the file, as "packaging" your app is something that happens "towards the end" of the development cycle.
Another option: SBT automatically combines the contents of all .sbt files it finds in the project root. So if you prefer, you could create a new file such as packagingSettings.sbt and put those settings in there.
Edit: Help with imports:
Whichever option you choose, you'll need to add the following imports at the top of the file (as per the getting started guide):
import com.typesafe.sbt.SbtNativePackager._
import NativePackagerKeys._

Related

Spark-Scala build.sbt libraryDependencies UnresolvedDependency

i'm trying to import a dependency in my build.sbt file from here
https://github.com/dmarcous/spark-betweenness.
When i hover on the error it says:
Expression type ModuleID must confirm to Def.SettingsDefinition in SBT file
Unresolved Dependency
I am new in scala so my question may be silly.Thanks in advance
It is still unclear how your build configuration looks like, but the following build.sbt works (in the sense that it compiles and does not show the error that you mentioned):
name := "test-sbt"
organization := "whatever"
version := "1.0.0"
scalaVersion := "2.10.7"
libraryDependencies += "com.centrality" %% "spark-betweenness" % "1.0.0"
Alternatively, if you have a multi-project build, it could look like this:
lazy val root = project
.settings(
name := "test-sbt",
organization := "whatever",
version := "1.0.0",
scalaVersion := "2.10.7",
libraryDependencies += "com.centrality" %% "spark-betweenness" % "1.0.0"
)
However, you're probably going to find that it still does not work because it cannot resolve this dependency. Indeed, this library does not seem to be available neither in Maven Central nor in jcenter. It is also very old - it appears to only be published for Scala 2.10 and a very old Spark version (1.5), so most likely you won't be able to use it with recent Spark environments (2.x and Scala 2.11).

How to activate the sbt DockerPlugin in scala?

I have two scala projects, one is already defined to build its docker container through the sbt docker plugin. The other one I want to dockerify as well.
The working one has in its build.sbt the following lines relevant to the docker config:
organization := "com.namespace"
name := "dockerized-app"
version := sys.env.getOrElse("PIPELINE_VERSION", "0.1.0_local")
scalaVersion := "2.12.4"
enablePlugins(JavaAppPackaging)
enablePlugins(DockerPlugin)
packageName in Docker := packageName.value
dockerRepository := Some("our-docker.io:5001")
dockerExposedPorts := Seq(8080)
I thought that I could copy paste the relevant lines to the new project, change the name, and make it work.
Yet when I add the line to the about to be dockerified scala project:
enablePlugins(DockerPlugin)
I get the error:
Cannot resolve symbol DockerPlugin
I've looked through the prexisting projects libraryDependencies, yet it doesn't seem to be configured that way. In the the pre-configured project, IntellJ somehow knows the plugin, I can track that the DockerPlugin comes from com.typesafe.sbt.packager.docker. This made me assume that sbt comes shipped with it by default.
Yet apparently I have to activate it somehow.
Digging deeper I also tried adding this to my plugins.sbt to no avail:
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.2")
How to activate DockerPlugin using sbt in scala?
In order to make it working properly you need to add the following line:
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.2")
in your project/plugins.sbt file.
Then refresh your project and it should work.
For further information, please check the Sbt Native Packager documentation.

sbt not resolving dependency; path correct except ${package.type} extension

sbt (0.13.8) is failing to resolve the dependency in the following extremely simple build.sbt:
organization := "edu.umass.cs.iesl"
name := "nn-depparse"
version := "0.1-SNAPSHOT"
scalaVersion := "2.11.7"
resolvers += "IESL snapshot repository" at "https://dev-iesl.cs.umass.edu/nexus/content/repositories/snapshots/"
libraryDependencies += "cc.factorie" %% "factorie" % "1.2-SNAPSHOT"
parallelExecution := true
For some reason it resolves the following path:
https://dev-iesl.cs.umass.edu/nexus/content/repositories/snapshots/cc/factorie/factorie_2.11/1.2-SNAPSHOT/factorie_2.11-1.2-20151007.170205-28.${package.type}
Rather than the correct path to the jar:
https://dev-iesl.cs.umass.edu/nexus/content/repositories/snapshots/cc/factorie/factorie_2.11/1.2-SNAPSHOT/factorie_2.11-1.2-20151007.170205-28.jar
It seems as though ${package.type} is being interpreted as a literal file extension rather than whatever the contents of the variable package.type, but I have no idea why; I am using the simplest possible build configuration! As far as I know, I don't have any weird sbt configurations lying around (or any at all -- I checked ~/.sbt, and I have tried running on multiple machines).
As #kawty says it does look like the pom in question is malformed, but in terms of fixing your sbt script, you can change you dependency line to:
libraryDependencies += "cc.factorie" %% "factorie" % "1.2-SNAPSHOT" artifacts( Artifact("factorie", "", "jar"))
to manually specify the extension of the artifact that you want.
A following line found in factorie_2.11-1.2-20151007.170205-28.pom:
<packaging>${package.type}</packaging>
I suppose sbt uses this setting to get the artifact.
In the previous .pom file, it has:
<packaging>jar</packaging>
So, maybe it's a broken build.

How to set up managed dependencies in an SBT 0.11 project having Build.scala

I am building a simple Scala project with SBT 0.11.
All the code files are in ~/MyProject/src/main/scala/
~/MyProject/build.sbt is the following
name := "MyProject"
version := "1.0"
scalaVersion := "2.9.1"
libraryDependencies ++= Seq(
"mysql" % "mysql-connector-java" % "5.1.+",
"c3p0" % "c3p0" % "0.9.1.2",
"org.apache.commons" % "commons-lang3" % "3.0.1",
"commons-lang" % "commons-lang" % "2.6",
"javassist" % "javassist" % "3.12.1.GA"
)
~/MyProject/project/Build.scala is the following
import sbt._
object MyProjectBuild extends Build {
lazy val MyProject = Project("MyProject", file("."))
}
This seems to work almost fine. The project does compile and run. The project name is set correctly (if I don't use Build.scala, then the name seems to appear something like "default-????", despite it being specified in build.sbt).
But the problem is that dependencies do not seem to work - update command doesn't download anything. How to fix this? Do I need to specify my dependencies in Build.scala rather than in build.sbt in this case?
Is it possible that you've already retrieved the project dependencies, but don't realize it because they are stored in the Ivy cache? You can view the managed classpath from the SBT console with the command
show managed-classpath
Recent versions of SBT do not store the managed dependencies in the project directory, unless the project is configured to do so. If you want, you can add the following to your build.sbt file:
retrieveManaged := true
This will create a ~/MyProject/lib_managed/ directory and contents.

How to change SBT's rules on generating URLs for Maven repositories?

By default, the Scala Built Tool (SBT) has a set of rules on how to generate URLs when looking up dependencies. For example, if I have the following build file,
// Project settings
name := "MyProject"
version := "0.1"
organization := "com.me"
scalaVersion := "2.8.1"
// Dependencies
libraryDependencies ++= Seq(
"com.google.guava" %% "guava" % "r09"
)
// Repositories
resolvers += "Maven Central Server" at "http://repo1.maven.org/maven2"
Then SBT attempts to find guava at the following URL,
http://repo1.maven.org/maven2/com/google/guava/guava_2.8.1/r09/guava_2.8.1-r09.pom
However, the library I'm looking for in this case isn't even made for Scala, so combining the Scala version just doesn't make sense here. How can I tell SBT what the format is for generating URLs for use with Maven repositories?
EDIT
While it seems that it is possible to edit the layout like so,
Resolver.url("Primary Maven Repository",
new URL("http://repo1.maven.org/maven2/"))( Patterns("[organization]/[module]/[module]-[revision].[ext]") )
the "[module]" keyword is predefined to be the (artifact id)_(scala version) and the "[artifact]" keyword is just "ivy", leaving me back at square one.
As far as I remember "%%" appends the scala version and "%" does not. Try
libraryDependencies ++= Seq(
"com.google.guava" % "guava" % "r09"
)
Check last one paragraph (Custom Layout) of official sbt wiki here.
Basically SBT allows you to use this syntax:
resolvers += Resolver.url("my-test-repo", url)( Patterns("[organisation]/[module]/[revision]/[artifact].[ext]") )