I have my project (just for experiments with sbt) which is based on sbt 0.10. And another one which I want to use as a dependency. It is sbt 0.7 based.
Currently I'm trying to include the second it into my project project using uri reference. But the build is failing, probably because of incompatible versions of sbt in these projects. The error message is:
[info] Compiling 1 Scala source to /home/zan/.sbt/staging/113d72bca54918c1f033/project/plugins/target/scala-2.8.1.final/classes...
[error] /home/zan/.sbt/staging/113d72bca54918c1f033/project/plugins/Plugins.scala:1: not found: value sbt
[error] import sbt._
[error] ^
[error] /home/zan/.sbt/staging/113d72bca54918c1f033/project/plugins/Plugins.scala:3: too many arguments for constructor Object: ()java.lang.Object
[error] class Plugins(info: ProjectInfo) extends PluginDefinition(info) {
[error] ^
... and so on.
Can I somehow reference the second project so it will be possible to bild and/or run my project with just one command?
SBT cross-project references are only supported if both projects use SBT 0.10. But you can use publish and artifact and depend on this from the downstream project through Ivy.
Issue the publish-local command in the first project to package the code in a JAR and write it to ~/.ivy2/local/org.abc.def/....
In the SBT 0.10 project, add this setting:
libraryDependencies += "org.abc" %% "def" % "0.1"
Related
I'm making a project in Scala (2.11), using Maven as my build tool. I'd like to use this library, but I can't get it to work.
I have a minimal (2 files) example repository here: https://github.com/evertheylen/scala-maven-bintray-example
I added two dependencies, kafka and scala-kafka-client. Both times I followed the instructions on their respective websites, but the last one (from bintray) is giving me problems. I would like the repository to be defined in the project, and not in my personal settings.xml (though I did try that and it didn't work).
The error given to me by mvn package exec:java -Dexec.mainClass=be.evertheylen.SampleApplication is:
[ERROR] .../src/main/scala/SampleApplication.scala:3: error: not found: object cakesolutions
[ERROR] import cakesolutions.kafka.KafkaProducer
[ERROR] ^
[ERROR] .../src/main/scala/SampleApplication.scala:4: error: not found: object cakesolutions
[ERROR] import cakesolutions.kafka.KafkaProducer.Conf
[ERROR] ^
[ERROR] two errors found
Although mvn dependency:list does in fact list the library:
[INFO] The following files have been resolved:
...
[INFO] net.cakesolutions:scala-kafka-client_2.11:pom:0.10.0.0-RC2:compile
...
Try removing <type>pom</type> from the dependency declaration in your pom.xml.
I am having problems compiling a Java dependency loaded via GIT:
object ApplicationBuild extends Build {
lazy val project = Project("root", file(".")).dependsOn(RootProject(riakJavaClient))
lazy val riakJavaClient = uri("git://github.com/basho/riak-java-client")
}
The error I am receiving from sbt compile is:
[info] Compiling 134 Java sources to /Users/lawrencewagerfield/.sbt/0.13/staging/da0e66c4764a467c8977/riak-java-client/target/scala-2.10/classes...
[error] /Users/lawrencewagerfield/.sbt/0.13/staging/da0e66c4764a467c8977/riak-java-client/src/main/java/com/basho/riak/client/cap/Quorum.java:22: error: unmappable character for encoding ASCII
[error] * Riak 0.12 introduced ???symbolic??? consistency options for R and W
SBT seems to be executing javac with an encoding that is incompatible with the source files in this dependency.
I have tried adding the following to build.sbt, but it is having no effect (error is the same):
javacOptions ++= Seq("-encoding", "UTF-16") // Note: I have tried with UTF-8 too
Does the above only apply to source files within my project? Any idea how to get pass this issue?
TL;DR How do I get my Java dependencies compiling with the correct encoding?
You are correct that the setting only applies to source files in your project. If the project part of the scope isn't specified, which is typical, it defaults to the enclosing project. To have a setting apply to another project, scope it to that project. For example,
javacOptions in riakJavaClient ++= Seq("-encoding", "UTF-8")
You can verify that your options are being used with last. For example,
sbt> last compile
To run commands like the above on a project from git, change to it using project (see help project for details).
I'm trying out sbt's direct dependsOn feature with a git repository ("project A") hosted at Github. I am using a stable tag reference, and in my test project ("project B"), sbt does clone project A from source and starts compiling. However compilation fails with project A's own dependencies seemingly missing (i.e. it doesn't seem to pick up anything defined in project A's build.sbt).
Is this a different from maven/ivy managed dependencies? Do I need to include all the transitive dependencies in my child project B? Sounds a bit weird to me. That would kind of kill off the whole effort, as I'm having like a dozen libraries on which project A depends.
To illustrate:
Project A (online on Github as source):
// build.sbt:
version := "1.2.3"
libraryDependencies += "org.foo" %% "bar" % "1.0"
Project B (local):
// project/Build.scala
import sbt._
import Keys._
object Build extends sbt.Build {
lazy val projA = RootProject(uri("git://github.com/me/projA.git#v1.2.3"))
lazy val projB = Project(id = "project-B", base = file(".").dependsOn(projA)
}
This goes:
[info] Compiling 678 Scala sources to /Users/me/.sbt/staging/
5666eafa865fdf605be3/target/scala-2.10/classes...
[error] /Users/me/.sbt/staging/5666eafa865fdf605be3/src/main/scala/com/me/
BarKeeper.scala:3: not found: object bar
[error] import org.foo.bar
[error] ^
So do I have to re-declare the library dependency on "org.foo" %% "bar" % "1.0"? I hope not!
This was purely my own fault, not sbt's. I had overseen an unmanaged library (folder lib) in project A. After exchanging it for a Maven managed version (folder lib_managed), project A now correctly compiles from source in the staging for project B.
I'm developing a simple SBT project that includes InputTasks for benchmarking Scala Parallel collections.
I have defined the InputKeys and started writing the tasks when I encountered a problem.
Since my benchmarks require Scala 2.10.0-M5, I tried doing this in my build.sbt:
name := "scala-parallel-collection-benchmark"
version := "1.0.0"
organization := "com.google.summer"
scalaVersion := "2.10.0-M5"
However, at compilation I get the following error:
[info] Loading project definition from C:\Users\Administrator\scala-parallel-collection-benchmark\project
[info] Compiling 1 Scala source to C:\Users\Administrator\scala-parallel-collection-benchmark\project\target\scala-2.9.1\sbt-0.11.3\classes...
[error] C:\Users\Administrator\scala-parallel-collection-benchmark\project\Build.scala:47: value tasksupport is not a member of scala.collection.parallel.mutable.ParArray[Int]
[error] collection.tasksupport = new ForkJoinTaskSupport(new ForkJoinPool(par))
[error] ^
[error] one error found
[error] {file:/C:/Users/Administrator/scala-parallel-collection-benchmark/project/}default-e0b2a2/compile:compile: Compilation failed
It appears that it still uses Scala 2.9.1 to compile it.
How can I set up SBT so it compiles my code using Scala 2.10.0-M5?
scalaVersion only impacts the version of Scala used to compile the "actual" source code (usually located in src/...). Your error comes from a part of the build definition (under project/), which is always compiled with the Scala version that sbt was built with.
You can't modify the version of Scala that is used to to compile the project definition, because it must be a version binary compatible with the version used to compile SBT itself. There's some flexibility being studied in this regard, but, right now, it's fixed.
The setting scalaVersion will change the version of Scala used to compile the project itself. The project can be compiled with completely different versions and, in fact, you can even have SBT compile your project with multiple Scala versions.
you can change the scala version in file "project/build.properties"
e.g. sbt.version=0.11.2
I am trying to get started with the Lift framework, reading Lift in Action. I would like to follow along with the examples, but I immediately stumble into a problem with installing Lift. I know that there are various ways to get started easily with Lift, but I would like to use Lifty, as the book does, to be able to follow it.
The problem is that both Lifty and sbt (and Lift too!) have moved forward since the book was published. I installed sbt from the Typesafe repository for Ubuntu. Now I am stuck trying to install Lifty.
Following Lifty documentation and this answer on SO - due to the fact that Lifty has not released a binary for sbt 0.11.3 - I figured I should put the following in ~/.sbt/plugins/build.sbt:
resolvers += Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
addSbtPlugin("org.lifty" % "lifty" % "1.7.4")
libraryDependencies +=
Defaults.sbtPluginExtra(
"org.lifty" % "lifty" % "1.7.4",
"0.11.2",
"2.9.1"
)
The latter is to tell sbt to use the Lifty plugin for sbt 0.11.2.
Now sbt seems to be able to download Lifty and starts correctly, but I do not have a lifty command. So when I do
lifty learn lift https://raw.github.com/Lifty/lifty/master/lifty-recipe/lifty.json
sbt complains:
[error] Not a valid key: lifty (similar: history)
[error] lifty learn lift https://raw.github.com/Lifty/lifty/master/lifty-recipe/lifty.json
[error] ^
How should I install Lifty? Please note that I am new to Scala, sbt and Lift.
EDIT
I managed to install Lifty by downgrading to sbt 0.7.7. But then if I do
> lift create project-blank
> reload
> update
I get the error
[error] sbt.ResolveException: unresolved dependency: net.liftweb#lift-webkit_2.9.1;2.3-RC3: not found
[error] unresolved dependency: org.scala-tools.testing#specs_2.9.1;1.6.6: not found
[info] == update ==
[error] Error running update: sbt.ResolveException: unresolved dependency: net.liftweb#lift-webkit_2.9.1;2.3-RC3: not found
[error] unresolved dependency: org.scala-tools.testing#specs_2.9.1;1.6.6: not found
I hate to break it to you, but lifty is gone. As of this writing, sbt's stable is 0.13.0. Looking at sbt community repo, the only version that was released was 1.7.4 for sbt 0.11.2.
The official website says:
The Lift Cookbook is the most up-to-date resource to learn how to use Lift.
There's a section named Creating a Lift Project from Scratch Using SBT:
Problem
You want want to create a Lift web project from scratch without using the ZIP files provided on the official Lift website.
Solution
You will need to configure SBT and the Lift project yourself. Luckily, only five small files are needed.
First, create an SBT plugin file at project/plugins.sbt (all filenames are given relative to the project root directory):
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "0.3.0")
This file tells SBT that you will be using the xsbt-web-plugin.
Next, create an SBT build file, build.sbt...
Unfortunately xsbt-web-plugin 0.3.0 is for sbt 0.12. So you have to either use sbt 0.12, or modify the instruction a bit. The latest xsbt-web-plugin for sbt 0.13 is 0.4.2, so in project/plugins.sbt put:
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "0.4.2")
resolvers += Resolver.sonatypeRepo("public")
I was able to follow along with the rest of instructions on the page...
Eventually I got everything pulled in by sbt 0.13, and was able to start the container:
> container:start
[info] Compiling 1 Scala source to /foo/sbt-lift-test/target/scala-2.10/classes...
[info] jetty-8.1.7.v20120910
....
[success] Total time: 2 s, completed Sep 20, 2013 10:34:22 PM
Open http://localhost:8080/ using the browser:
Welcome, you now have a working Lift installation