How to get sbteclipse working with Scala 2.9 - eclipse

I am playing with the spray template project and Scala 2.9.0.1.
I want to work with Eclipse and so I've added the following lines to the build.sbt file
of the spray template project.
resolvers += {
val typesafeRepoUrl = new java.net.URL("http://repo.typesafe.com/typesafe/releases")
val pattern = Patterns(false, " [organisation]/[module]/[sbtversion]/[revision]/[type]s/[module](-[classifier])-[revision]. [ext]")
Resolver.url("Typesafe Repository", typesafeRepoUrl)(pattern)
}
libraryDependencies <<= (libraryDependencies, sbtVersion) { (deps, version) =>
deps :+ ("com.typesafe.sbteclipse" %% "sbteclipse" % "1.3-RC2" extra("sbtversion" -> version))
}
I always get this error:
com.typesafe.sbteclipse#sbteclipse_2.9.0-1;1.3-RC2: not found
Of course the directory at the typesafe server does not exist. There is only:
http://repo.typesafe.com/typesafe/releases/com.typesafe.sbteclipse/sbteclipse_2.8.1/
but sbt is trying to get:
http://repo.typesafe.com/typesafe/releases/com.typesafe.sbteclipse/sbteclipse_2.9.0-1/0.10.1/1.3-RC2/jars/sbteclipse_2.9.0-1-1.3-RC2.jar
I figured out that 2.8.1 is the scala version sbt uses internaly. But my
sbt version (0.10) uses the scala version set in the build.sbt (scalaVersion := "2.9.0-1") to build the url to download sbteclipse.
Does anyone know how to set this up correctly? How do I tell the build.sbt file that I want to use Scala 2.9 but to look for the sbteclipse plugin at the correct URL?
Are there any plans to include something like sbteclipse to the sbt standard distribution? That would be more than welcome and probably help a lot of beginners with Scala, sbt and Eclipse.
Claus

try some thing like "com.typesafe.sbteclipse" % "sbteclipse_2.8.1" % "1.3-RC2....."
using "%%" will automicly add scala version to the library name. using "%" will not.

There is also a shorter way to get sbteclipse into use. Create a file ~/.sbt/plugins/plugins.sbt with this content:
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.1.0")

Related

How to make IntelliJ scala project use Scala 2.9.2 version?

I'm trying to create jar file from scala file - which will be used for Scalatron bot (http://scalatron.github.io/)
The problem is that if I create jar file using new scala versions 2.10 - 2.13 (these are the only one's that InteliJJ allows me to use) scalatron bot doesn't work.
However I found out that downgrading to scala 2.9.2 fixes the problem (Getting Scalatron to Work (trouble with opcode)).
How to downgrade to 2.9.2 on Intellij?
SBT is fully integrated with IntelliJ Idea, so you can create a SBT project in IntlliJ and make up the build.sbt file by yourself and put in it the scala version you want, compile, package and execute with SBT
name := "scalatron"
version := "0.1"
scalaVersion := "2.9.2"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.2.0-SNAP3" % Test

Why can't sbt find my local package

Searching for examples of library use I downloaded this project.
https://github.com/marcusatbang/Hooks
I then moved the build.bat up one directory. Commented out the xsbt-gpg dependency lines in build.sbt and Build.scala since sbt couldn't find the package. I checked the source to comment out any imports of xsbt-gpg -- there were none. ( Surprise! )
So I managed to compile the project. I then did sbt publish-local. find ~/.ivy2 -iname "\*hooks*jar" generated the following line: .ivy2/local/cc.minotaur/hooks_2.9.0/0.1/jars/hooks_2.9.0.jar.
I then entered the examples folder and tried to build the example project.
The build.scala contains the line: libraryDependencies += "cc.minotaur" %% "hooks" % "0.1", and it generates the error: unresolved dependency: cc.minotaur#hooks_2.9.1;0.1: not found
So how do I fix this error? It seems to me it should be finding the hooks jar/
That could be that your resolver doesn't see local directory. Try something like:
val ivyLocal = Resolver.file("local", file(Path.userHome.absolutePath +
"/.ivy2/local"))(Resolver.ivyStylePatterns)
externalResolvers += ivyLocal
It seems to me that you are using two versions of Scala. The one you are generating the jar is 2.9.0 while the one you are using in the example project is 2.9.1. Probably will solve the problem setting the same version in both projects.
I think your scala version is 2.9.1, u have generated jar for version 2.9.0
change your library dependency as mentioned below.
libraryDependencies += "cc.minotaur" % "hooks_2.9.0" % "0.1"
or add scalaVersion := "2.9.0" in your build.sbt file

Using a 2.10-only SBT plugin in a project that's cross-built against 2.9

Suppose I've got a SBT 0.13 project that's cross-built against Scala 2.9.3 and 2.10.4. I want to use an SBT plugin (sbt-coveralls) for the 2.10 build only, because the plugin isn't available for 2.9.
I know that I could use CrossVersion to conditionally add the plugin settings to the 2.10 build, but that doesn't help with the fact that addSbtPlugin isn't going to find anything for the 2.9 build, etc.
I'm assuming this is impossible (short of some really messy ad-hoc shell scripting) but I'm not an SBT wizard, and it would be nice to be surprised by the mysteries of SBT in a good way for once.
Found this horrible hack of a workaround, but it does seem to work:
resolvers <++= scalaVersion {
case v if v startsWith( "2.12" ) =>
Seq.empty
case _ =>
addSbtPlugin( "org.scoverage" % "sbt-scoverage" % "1.0.4" )
addSbtPlugin( "org.scoverage" % "sbt-coveralls" % "1.0.0" )
Seq( Classpaths.sbtPluginReleases )
}
I might misunderstand the question, but I think you may be confused with sbt's vs a project's versions of Scala.
You cannot use a plugin that's incompatible with sbt - the runtime. If a plugin doesn't support the version of Scala sbt uses under the covers the plugin is deemed incompatible and hence sbt will refuse starting up. sbt 0.13.5 uses 2.10.4 so the plugins can only use Scala API 2.10.4. That's why addSbtPlugin offers no %%.
For projects, it's different. Here you could use whatever version you want regardless of the version sbt uses and hence the plugins. Once you've addSbtPlugin'ed a plugin, the plugin's available in a project, and to enable it, add the settings to projects.

sbt version and scala version. project configuration for intellij idea with sbt-idea plugin

I follow these steps to configure a project for IntelliJ idea.
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0")
I use sbt-idea for sbt version 0.12 with fixed bug for Idea.
When I type sbt in my project's directory, I noticed that it uses scala 2.9.2.. but I'm going to use scala 2.10.1 for my project.
Questions:
Does it make sense which scala version to use for plugin(s) (~/.sbt/plugins)-compilation, or I should use one/same scala version for everything? Can I change scala version for plugins?
So, I created ~/.sbt/plugin/build.sbt file with mentioned content.
that version is out of date, it depends on sbt-idea 1.2.0-SNAPSHOT. The latest at the time of writing is 1.3.0
See my project skeleton for an implementation using the latest versions of scala, scalatest and SBT to IDE project plugins.
Actually I got it.
if you have a project with build.sbt (that uses 2.10.1 scala) file - as soon as you type sbt.. all dependencies will be downloaded into ~/.sbt folder - even scala compiler will be downloaded there (~/.sbt/boot). It could be even several version of scala: 2.10.1 and 2.9.2 for example.
and about sbt-idea and ~/sbt/plugins .. it could any scala version - depending on its build.sbt file, for example in my case:
resolvers += "Sonatype snapshots" at
"http://oss.sonatype.org/content/repositories/snapshots/"
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.2.0-SNAPSHOT")
I should notice if try different version.. like 1.1.0-M2-TYPESAFE it will not work.. (at least in my case) - gen-idea command is not available then. I do not know why. I guess it should.
Also if you do not point resolvers += - it will will not work.. but it it will not tell you about that..
This plugin is using scala 2.9.2 - we can not see it here, but we can see it from that outputs it produces while installing/downloading. That's why we have ~/.sbt/boot/scala-2.9.2/ as a result.
In any case we should not care about it. It is handled by sbt.
When you converted your sbt-project into your intellij-idea project by typing gen-idea in sbt console, as the result your IDE project will be referencing to ~/.sbt/scala but not to your somewhere-installed-scala.. So even no need to pointing the scala location - that sbt-idea sbt's plugin will do all the work. And that's good!
That's the answer I wanted to get. One gets/understands it by trying it.

scala + mongoDB how to?

I am following http://api.mongodb.org/scala/casbah/current/setting_up.html in order to use MongoDB with scala.
I am new to sbt as well. The above starting up guide says:
1.1.5. Setting up SBT
Finally, you can add Casbah to SBT by adding the following to your
project file:
val casbah = "com.mongodb.casbah" %% "casbah" % "2.1.5.0" The double
percentages (%%) is not a typo—it tells SBT that the library is
crossbuilt and to find the appropriate version for your project’s
Scala version. If you prefer to be explicit you can use this instead:
// Scala 2.8.0 val casbah = "com.mongodb.casbah" % "casbah_2.8.0" %
"2.1.5.0" // Scala 2.8.1 val casbah = "com.mongodb.casbah" %
"casbah_2.8.1" % "2.1.5.0" // Scala 2.9.0.1 (don't use Scala
2.9.0.final; 2.9.0.1 contains critical fixes) val casbah = "com.mongodb.casbah" % "casbah_2.9.0-1" % "2.1.5.0" Don’t forget to
reload the project and run sbt update afterwards to download the
dependencies (SBT doesn’t check every build like Maven).
My question is what does first line mean, "adding following line to your project file".
My understanding about adding dependancy is:
add following line to build.sbt file
dependancies += "com.mongodb.casbah" % "casbah_2.9.0-1" % "2.1.5.0"
Then do sbt update
But, when I do sbt update, I get following error:
[error] {file:/Users/hrishikeshparanjape/git-public/ws/}default-1efcb1/*:update: sbt.ResolveException: unresolved dependency: com.mongodb.casbah#casbah_2.9.0-1;2.1.5.0: not found
[error] Total time: 1 s, completed Jul 26, 2012 9:32:59 PM
In short, I did not understand that getting started page.
EDIT
my build.sbt file:
name := "ws"
version := "0.1"
libraryDependencies += "com.mongodb.casbah" % "casbah_2.9.0-1" % "2.1.5.0"
My directory structure(basicmost nothing added yet)
ws
-build.sbt
I think you need to add a resolver to your build.sbt file.
resolvers += "snapshots" at "https://oss.sonatype.org/content/repositories/snapshots"
resolvers += "releases" at "https://oss.sonatype.org/content/groups/scala-tools"
More info on sbt can be found here. Going through it is very helpfull in understanding the basics of sbt:
A lot of time has passed but I would like to share an update for those, who may search for Scala MongoDB client library.
We have published the Scala library that wraps original mongodb-core in the Scala manner. The API is much more convenient that the mongo-scala-driver from MongoDB for Scala and fully asynchronous. Instead of callbacks we expose Futures and for those with more sophisticated needs the RXScala observables.
If you'r using Play Framwork 2.4 there is a module with ready to use formatters for Json: https://github.com/evojam/play-mongodb-driver
With the Play Framework module it's pretty straightforward to start, like few minutes to get working code.
This way MongoDB is nice and easy to use in Scala. We have provided a comparison of the sample query execution is in our blog post about the driver on site.