I'm trying to get an rpm built that uses the Systemd archetype. However, I'm getting errors on my import in build.sbt. I am using sbt version 0.13.11 Specifically, I am seeing:
build.sbt:3: error: object systemloader is not a member of package com.typesafe.sbt.packager.archetypes
I'm trying to use version 1.1.4 of sbt-native-packager. Here is my plugins.sbt:
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// The Sonatype snapshots repository
resolvers += "Sonatype snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.1.4")
My build.sbt:
import com.typesafe.sbt.packager.linux.LinuxSymlink
import com.typesafe.sbt.packager.rpm.RpmPlugin.autoImport._
import com.typesafe.sbt.packager.archetypes.systemloader._
scalaVersion := "2.11.7"
name := "systemdtest"
organization := "myTestOrg"
enablePlugins(JavaServerAppPackaging, RpmPlugin, SystemdPlugin)
version := "1.0"
// RPM SETTINGS
rpmVendor := "me"
packageSummary in Linux := "A summary"
packageDescription := "Do some stuff"
rpmRelease := "1"
rpmBrpJavaRepackJars := false
rpmLicense := Some("Copyright this project")
rpmGroup := Some("mygroup")
rpmPrefix := Some("/opt/mypath")
I am getting the error when I try to run
sbt stage
or
sbt rpm:packageBin
The documentation for 1.1 on the native packager site (http://www.scala-sbt.org/sbt-native-packager/archetypes/systemloaders.html) says to use an auto-plugin called SystemdPlugin.
However, this does not exist in the 1.1 branch, and was introduced in the 1.2 branch that is (at time of this post, is 1.2.0M3), and not yet GA.
The correct convention is to add an assignment in your build.sbt called "serverLoading."
In my case, to use with an RPM, I needed to change my build.sbt to the following:
import com.typesafe.sbt.packager.rpm.RpmPlugin.autoImport._
import com.typesafe.sbt.packager.archetypes.ServerLoader
scalaVersion := "2.11.7"
name := "systemdtest"
organization := "myTestOrg"
enablePlugins(JavaServerAppPackaging)
version := "1.0"
// RPM SETTINGS
rpmVendor := "me"
packageSummary in Linux := "A summary"
packageDescription := "Do some stuff"
rpmRelease := "1"
rpmBrpJavaRepackJars := false
rpmLicense := Some("Copyright this project")
rpmGroup := Some("mygroup")
rpmPrefix := Some("/opt/mypath")
//THIS IS THE KEY PIECE!!
serverLoading in Rpm := ServerLoader.Systemd
I found my solution reading through the comments on this issue. https://github.com/sbt/sbt-native-packager/pull/785
sbt native-packager 1.2.0 i s almost released (Nov. 2016) and Muki Seiler details this new feature coming form PR 785:
Systemloaders are AutoPlugins now
Previously, the Java Server Application Archetype provided a setting serverLoading where you could define your system loader like this:
import com.typesafe.sbt.packager.archetypes.ServerLoader
serverLoading in Rpm := ServerLoader.Upstart
This adds the necessary configuration files and maintainer scripts (postinst, postun, etc. ) in order to register and start your application.
The biggest problem with the tight coupling between the server archetype and the systemloaders is that it’s hard to add systemloader specific settings without changing a lot in the server archetype.
It’s also a lot harder to reason about the code and the output.
With extra systemloader plugins we open the possibility to
easily extend a single systemloader
have a place to put generic systemloader functionality ( there is a SystemLoaderPlugin which takes care of common settings )
test systemloaders in isolation
better developer experience
You enable a systemloader by enabling a concrete systemloader plugin
enablePlugins(SystemdPlugin)
Related
I am working on a Scala extension for NetLogo (repo). I am following both the Extension API example and NetLogos Sample-Scala-Extension.
I am seeing:
[info] Done packaging.
To compare two paths outside a working tree:
usage: git diff [--no-index] <path> <path>
[warn] working tree not clean when packaging; target not created
[success] Total time: 6 s, completed Jan 29, 2019, 6:22:00 PM
The .jar that is generated does not contain modifications I made to the extension. I think it has something to do with "[warn] working tree not clean...".
Is this the case?
What is the solution?
File hierarchy:
Scala-Plume-Model
build.sbt
src
PlumeModelExtension.scala
build.sbt
enablePlugins(org.nlogo.build.NetLogoExtension)
name := "plume-scala"
version := "0.1"
scalaVersion := "2.12.0"
netLogoExtName := "plume-scala"
netLogoClassManager := "PlumeModelExtension"
netLogoZipSources := false
scalaSource in Compile := baseDirectory.value / "src"
scalacOptions ++= Seq("-deprecation", "-unchecked", "-Xfatal-warnings", "-encoding", "us-ascii")
netLogoVersion := "6.0.4"
The short answer: add isSnapshot := true to your build.sbt and then the package sbt task should start creating the output jar and zip files regardless of the current status of git.
Longer answer: The NetLogo Extension SBT plugin has some expectations about when packaging will occur. If isSnapshot is false or unset, the plugin assumes you're trying to do a "production" release. But for a production release you probably do not want to compile and package off of a dirty repository. So it warns you and does not create the artifacts.
The normal workflow would be to keep isSnapshot := true while you're in development, then once you have all your commits done and are ready for a release, add a commit to set isSnapshot := false (maybe along with a version bump for the extension), package and tag the release, then add a commit setting isSnapshot := true right away.
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).
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._
I have a scala play application; I am trying to expose health check for our service. Part of the health check I would like to capture the project artifact version.
Can I know how I can reference project artifact version from health check controller in play application. We are making use of sbt for the build.
sample sbt file
import root.sbt.Keys._
import com.typesafe.sbt.SbtNativePackager._
import NativePackagerKeys._
import play.PlayScala
name := "artifact-name"
version := "0.5"
scalaVersion := "2.11.1"
javacOptions ++= Seq("-source", "1.7", "-target", "1.7")
scalacOptions += "-target:jvm-1.7"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
The xsbt-reflect plugin gives you access to the SBT variables at runtime.
All you need to do inside of your health route is return
Reflect.version
When I run sbt publishLocal, the plugin will be generated in <ivy-repository>/<org>/<plugin>/<scala-version>/<sbt-version>/<plugin-version>/...
For example:
[info] published sbt-cloudengine to /Users/hanxue/.ivy2/local/net.entrypass/sbt-cloudengine/scala_2.10/sbt_0.13/0.2.1/jars/sbt-cloudengine.jar
How can I exclude <scala-version> and <sbt-version> from the output path?
This path is causing resolution failure when I add the plugin as a dependency in build.sbt:
[warn] ==== Local Ivy Repository: tried
[warn] file:///Users/hanxue/.ivy2/local/net/entrypass/sbt-cloudengine/0.2.1/sbt-cloudengine-0.2.1.pom
Plugin's build.sbt is:
sbtPlugin := true
name := "sbt-cloudengine"
organization := "net.entrypass"
version := "0.2.1"
description := "sbt plugin for managing Google Cloud Engine resources"
licenses := Seq("BSD License" -> url("https://github.com/hanxue/sbt-cloudengine/blob/master/LICENSE"))
scalacOptions := Seq("-deprecation", "-unchecked")
publishArtifact in (Compile, packageBin) := true
publishArtifact in (Test, packageBin) := false
publishArtifact in (Compile, packageDoc) := false
publishArtifact in (Compile, packageSrc) := false
publishMavenStyle := false
Update 1
This is how the plugin is referenced in a project's <rootdir>/build.sbt
resolvers += "Local Ivy Repository" at "file://"+Path.userHome.absolutePath+"/.ivy2/local"
libraryDependencies ++= Seq(
"net.entrypass" % "sbt-cloudengine" % "0.2.1"
)
This is the directory listing
$ ls -R ~/.ivy2/local/net.entrypass/sbt-cloudengine/scala_2.10/sbt_0.13/0.2.1/
ivys jars poms
/Users/hanxue/.ivy2/local/net.entrypass/sbt-cloudengine/scala_2.10/sbt_0.13/0.2.1//ivys:
ivy.xml ivy.xml.md5 ivy.xml.sha1
/Users/hanxue/.ivy2/local/net.entrypass/sbt-cloudengine/scala_2.10/sbt_0.13/0.2.1//jars:
sbt-cloudengine.jar sbt-cloudengine.jar.sha1
sbt-cloudengine.jar.md5
/Users/hanxue/.ivy2/local/net.entrypass/sbt-cloudengine/scala_2.10/sbt_0.13/0.2.1//poms:
sbt-cloudengine.pom sbt-cloudengine.pom.sha1
sbt-cloudengine.pom.md5
Since you're publishing a sbt plugin and not a library, the path will correctly contain the sbt version and the scala version.
Your problem comes from the fact you're trying to load the plugin using the libraryDependencies. Instead, you have to use the file project/plugins.sbt with the following inside:
addSbtPlugin("net.entrypass" % "sbt-cloudengine" % "0.2.1")
This way, sbt will search the plugin using the correct path with the help of the current scala and sbt versions.