Lifty and SBT 0.12 - scala

I'm new to using SBT, and I'm trying to install and configure Lifty, however when I try to run sbt, I get the following error:
[error] (*:update) sbt.ResolveException: unresolved dependency: org.lifty#lifty;1.7.4: not found
As per the Installing the Plugin instructions for Lifty, my ~/.sbt/plugins/build.sbt file looks like:
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")
And my ~/.sbt/build.sbt file includes the line:
seq( Lifty.liftySettings : _*)
However, when trying to run this, I get the SBT error listed above, and I get a similar error if I try to use the 1.7.5-SNAPSHOT version of Lifty instead.
I'm using SBT launcher version 0.12.0 and Scala version 2.10.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_17) on Ubuntu 12.10.
Thank you!

You are using the wrong definition. Here is what you need;
resolvers += Resolver.url("sbt-plugin-snapshots", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-snapshots/"))(Resolver.ivyStylePatterns)
addSbtPlugin("org.lifty" % "lifty" % "1.7.4")
If you want to make this available for all projects, then put in ~/.sbt/plugins/plugins.sbt. Otherwise it goes in: ProjectFolder/project/plugins.sbt
But they don't have a Scala 2.10 or SBT 0.12 release out.. Look HERE for what is available.

Related

SBT dependency error for Scala Spark on Intellij

I am a noob to Spark and Intellij.I want to run Spark using Scala
I initially installed Scala 2.12 and created the SBT accordingly.Then I got a NoSuchMethod runtime error on
sc = new SparkContext(conf)
From the solution posted NoSuchMethodError when using Sparka and IntelliJ I used Scala version 2.11.3 while creating the project and used the SBT
version := "0.1"
scalaVersion := "2.11.3"
libraryDependencies += "org.apache.spark" % "spark-core_2.11" % "2.0.2"
I am now getting the error
Error:scalac: No 'scala-library*.jar' in Scala compiler classpath in Scala SDK SBT: org.scala-lang:scala-library:2.11.3:jar
This is the library on the External libraries section
I tried creating the project from scratch and Cache Invalidate/Restart option.Same result
I also tried downloading via Maven through File -> Project Structure.Only found spark-core 2.10.Showed the same NoSuchMethod Error
Can anyone identify the problem?
It clearly says that, It could not find scala-library*.jar file
So go to
"Project Structure -> Modules"
And see these jar files
scala-compiler.jar, scala-library.jar, scala-reflect.jar
If they are absent from the Modules add them manually or Reinstall the scala and scala plugin.
Hope this should work!

How to create executable jar in scala which can run on jvm?

I am using scala version 2.11.4, I have tried various options like sbt-assembly, build artifact (Intellij Idea feature), sbt package. Unfortunately, none of them worked form me.
I attempted following things :
With sbt-assembly :
Created assembly.sbt file and added following line :
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.12.0")
build.sbt :
scalaVersion in ThisBuild := "2.11.4"
resolvers += Resolver.url("bintray-sbt-plugins", url("http://dl.bintray.com/sbt/sbt-plugin-releases"))(Resolver.ivyStylePatterns)
ivyScala := ivyScala.value map { _.copy(overrideScalaVersion = true) }
I got the following error
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.eed3si9n:sbt-assembly:0.12.0 (sbtVersion=0.13, scalaVersion=2.11)
With 'build artifact' feature using Intellij Idea 15
Able to create a jar. However, not able to execute it. Was getting following error:
Invalid or corrupt jarfile
For this I tried the command : java -jar JAR_FILE
With sbt package :
Able to create JAR. However, not able to execute it. Was getting following error :
java.lang.NoClassDefFoundError scala/Function0
I was trying with the command :
java -cp scala-library.jar -jar JAR_FILE
Resolved
I am able to create jar by switching to scala version 2.10.5 and then used sbt-assembly plugin. Slightly disappointed with the fact that there is no available solution to create executable jar with latest version of scala.
If you are using sbt-assembly plugin, the correct task to perform is called assembly. When using IntelliJ IDEA, sbt assembly needs to be performed from a command line, the IDE is still unable to perform such SBT tasks.
The resulting jar, which includes all dependencies, is usually called a fat jar - if you need some more searching, this is what to search for.
Since I can't comment yet, I'll use answer, but more of a question - I have been using sbt package extensively for exactly this. I cd into the directory that holds src/main/scala|java and running sbt package, and then pushing jar/war file to the desired destination, in my case jetty.
Can you explain exactly what you're doing, the output and details on the issue?

sbt is using wrong scala version rather than using the configuration in build.sbt

I have put these in the build.sbt file under current project's root directory
scalaHome := Some(file("/Users/ddam/scala-2.10.2"))
scalaVersion := "2.10.2"
And I ran sbt using
$ sbt --version
sbt launcher version 0.12.4
But still, I am seeing both the wrong version for sbt and scala when a particular dependency cannot be resolved
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.typesafe.sbteclipse:sbteclipse-plugin:2.4.0 (sbtVersion=0.12, scalaVersion=2.9.2)
Please help me.
It looks like sbteclipse requires SBT 0.13.0, and you are using version 0.12.4.
You can specify the SBT version by following the directions on this page.
Some other notes: You probably want to use Scala 2.10.3, not 2.10.2.
Also, it's strange to specify scalaHome; usually SBT will automatically fetch the needed Scala jars for you.
So to bootstrap a Scala environment, all you need to have installed are SBT and a JDK.
EDIT: (addressing comment below):
When you build code with SBT, you may actually use two different versions of Scala.
There is the version for SBT (what version of Scala the build system runs on), and the version for the code in your project (what version of Scala your code will run on).
The Scala version for SBT is determined by the SBT version you use.
If you use 0.12.4, SBT will run on Scala 2.9.3.
If you use 0.13.0, SBT will run on Scala 2.10.3.
You control the SBT version by following these instructions.
To control the version of Scala your project will run on, you can set scalaVersion in <projectRoot>/build.sbt.
So, you're getting that error because you're using SBT 0.12.4, which uses Scala 2.9.3.
SBT tries to find the sbteclipse plugin for 2.9.3, but it doesn't exist because it requires SBT 0.13.0 (=> Scala 2.10.3).
It seems you've correctly specified the use of Scala 2.10.2 for compiling your project.
sbt 0.12.4 always uses Scala 2.9.x to compile the build files (i.e. build.sbt and the stuff under project/). This means that plugins for sbt 0.12.x must also be compiled against 2.9.x, which explains what you're seeing.
sbteclipse 2.4.0 requires sbt 0.13. Try sbteclipse 2.2.0 if you want to stay on sbt 0.12.4.
emchristiansen's answer has good additional points.

sbt: cobertura4sbt cannot be found from sbt 0.12

I am about to use cobertura4sbt sbt plugin from maven repository.
I added the following lines to project\plugins.sbt:
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/groups/scala-tools"
addSbtPlugin("de.johoop" % "cobertura4sbt" % "1.0.0")
However, as I tried to "sbt compile", it always appended my local SBT and Scala version number to the resolving path so that the corresponding pom cannot be found. Do I miss something anywhere?
[warn] ==== Sonatype OSS Snapshots: tried
[warn] https://oss.sonatype.org/content/groups/scala-tools/de/johoop/cobertura4sbt_2.9.2_0.12/1.0.0/cobertura4sbt-1.0.0.pom
[warn] ==== public: tried
cobertura4sbt on sbt 0.7.4
The auto-postfixing of Scala and sbt version was added a while back in sbt to distinguish plugins for different releases of sbt. From this source, cobertura4sbt looks like it was built for 0.7.4, but the author says the plugin is no longer maintained:
This SBT plug-in enables you to measure your code coverage with the help of the great Cobertura tool.
However, since Cobertura is not really actively developed any more, I decided to stop working on this plugin for the time being, and instead started jacoco4sbt. Please ponder using jacoco4sbt instead of this plugin...
jacoco4sbt seems to be available for the latest sbt 0.13.0 too. Either plugin you choose, follow the instruction in the wiki.
jacoco4sbt on sbt 0.12.x
Given the log, I am assuming you're using sbt 0.12.x. jacoco4sbt for sbt 0.12 is published at Sonatype OSS, and the latest seems to be 2.0.0: https://oss.sonatype.org/content/groups/public/de/johoop/jacoco4sbt_2.9.2_0.12/2.0.0/
Try putting this in project/plugins.sbt:
resolvers += Resolver.sonatypeRepo("public")
addSbtPlugin("de.johoop" % "jacoco4sbt" % "2.0.0")
and in jacoco.sbt:
jacoco.settings
This loads jacoco:cover task into sbt shell, which I was able to run and get the report out in target/scala-2.10/jacoco directory.

Getting started with Lift and Lifty

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