I have an assignment to use some http client. I am planning to use scalaj-http for that. The installation page for that https://github.com/scalaj/scalaj-http, it says:
Installation
in your build.sbt
libraryDependencies += "org.scalaj" %% "scalaj-http" % "1.1.4"
But nothing is clearly mention, where do i need to do and what needs to be done? Is it command, or we have to paste this somewhere.
Can someone explain in detail?
You need to create an SBT project and add that library dependency in your build file. This link should help you to get started: http://www.scala-sbt.org/0.13/tutorial/Hello.html
Related
I am using a library say A in Scala which is dependent on version x.11 of another library say Z.
Now, I am also using a library say B which is dependent on version x.31 of Z.
This leads to compile error because we will have two versions of library Z, how can I use both libraries A and B in scala's sbt? Is there any way to specify it.
If completely replacing one dependency with a newer version happens to work, then Sparko's solution works. However, that isn't always the case.
If you want to include both versions of a library in the uber-jar produced by sbt-assembly, you'll need to use shading. See this post for an overview of what shading is, and some of the drawbacks associated with it.
Shading is covered in sbt-assembly's documentation here, but if you're anything like me, their way of explaining it will leave you more confused than you started. There's a good blog post, Spark, Uber Jars and Shading with sbt-assembly (waybackmachine link), that helps to demystify it a bit. Here's the relevant section:
I can shade over my typesafe config version, giving it a different
name so Spark won’t get confused between the versions. I quickly went
to my build.sbt file, and added the following code:
assemblyShadeRules in assembly := Seq(
ShadeRule.rename("com.typesafe.config.**" -> "my_conf.#1")
.inLibrary("com.typesafe" % "config" % "1.3.0")
.inProject )
According to the documentation, this should place any class under
com.typesafe.config under the new package my_conf.
For your case, the solution would be adding something like this to your build.sbt file:
assemblyShadeRules in assembly := Seq(
ShadeRule.rename("com.somecompany.**" -> "my_conf.#1")
.inLibrary("com.somecompany" % "libraryZ" % "0.11")
.inProject
)
In sbt, conflicts between libraries are configured using the conflict manager. By default, the latest revision is selected but this can also be overridden in you .sbt file:
conflictManager := ConflictManager.strict
If you're using sbt 0.13.6 or greater you will be warned when you have an incompatible binary version between your dependencies. In this situation, you could configure an override in your sbt file for the specific library:
dependencyOverrides += "org.raman" % "Z" % "x.11"
This will force the resolved version of Z to x.11 but not pull a direct dependency in.
I am working on an sbt project and I need to pull a jar, available via url, into my project as an unmanaged dependency.
As an example:
I want to retrieve a jar file available at
http://www.sourceGorge.net/fooProject/v4.2/lib/bar.jar. If the jar file is absent from myProject/lib then simply download the source jar, do nothing otherwise.
One possible solution I found on the web suggests the following:
libraryDependencies += "net.sf.proguard" % "proguard-base" % "5.0"
from "file:///tmp/proguard5.0beta2/lib/proguard.jar"
But my question would then be: what am I supposed to substitute for "net.sf.proguard", "program-base", and "5.0" if all I have is a url of the form specified in the above example?
Thank you in advance, and happy holidays if this is your holiday season.
If you're pulling the jar from a url, it doesn't matter what you call it--preferably something informative. sbt uses the organization/artifact/version to resolve dependencies from a repository. If you're providing an exact url, then it doesn't really matter.
For example, I can resolve joda-time like this, and it works just fine:
libraryDependencies += "doesn't" % "matter" % "2.1" from "http://central.maven.org/maven2/joda-time/joda-time/2.1/joda-time-2.1.jar"
It also uses the organization/artifact/version combination to store the jar in a specific directory in your local ivy repository. The above line downloaded the jar to:
~/.ivy2/cache/doesn't/matter/jars/matter-2.1.jar
how to use JavaCV from SBT (Simple Build Tool) in Scala? I need to use JavaCV so I can write a Scala application using this.
Simple Build Tool is here: http://www.scala-sbt.org/
JavaCV is here: http://code.google.com/p/javacv/
Add the following to your build.sbt file.
resolvers += "JavaCV maven repo" at "http://maven2.javacv.googlecode.com/git/"
libraryDepedencies += "com.googlecode.javacv" % "javacv" % "0.2"
This should pull down javacv for you, as well as any dependencies. Note you will still need to have all the native libraries set up like javacv details, this only gets the jars for your project.
I created an SBT plugin that solves most of this for you in 1 line; no need to set up native libraries etc because this will do it all for you.
https://github.com/lloydmeta/sbt-opencv
Usage:
Add the following in project/plugins.sbt:
addSbtPlugin("com.beachape" % "sbt-opencv" % "1.2")
On Github there is an description how to build the framework from scratch. How ever I want to understand how somethings work internally so I want to setup the Eclipse-IDE to make this as comfortable as possible. Has anyone a description how this can be easily done?
To make it clear, I don't want to know how to setup eclipse for working on play-project.
THIS SOLUTION WAS FOR PLAY 2.0, you can't use it directly in 2.1! at least the command build-repository isn't valid anymore.
git clone git://github.com/playframework/Play20.git
Add
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0")
to play20/framework/project/plugins.sbt, so you get
logLevel := Level.Warn
resolvers += Classpaths.typesafeResolver
addSbtPlugin("com.typesafe.sbtscalariform" % "sbtscalariform" % "0.3.0")
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0")
Then make the normal build processes.
$ cd Play20/framework
$ ./build
> build-repository
> eclipse
Create a Scala-IDE give her enough Space, choose the 64-bit variant if you can!
Import projects from play20/framework/src
Add /Play/target/scala-2.9.1/src_managed/main as source folder.
You will end up with less than 10 compilation errors :-(, but will have the most of the code in eclipse.
When building against 2.1 snapshot, Eclipse keeps the .ivy2/cache jar of play 2.0.1, which is where, in my case the errors were coming from.
The solution is to remove play 2.0.1 jar from eclipse build path, and add in the 2.1 snapshot jar that you build (in your-play20/repository/local/play/play_2.9.1/2.1-SNAPSHOT/jars)
Got an error free Eclipse + Scala-IDE setup, nice ;-)
Take a look at the Sbt eclipse Plugin. It will generate an eclipse project for you. It should be rather easy. Just follow the instruction on the plugins git page. Regards. Jan
Is there a command in the SBT console that forces it to resolve artifacts (especially, re-resolve SNAPSHOT dependencies)? The only way I know of now is to run clean and then compile (or start), but this takes much longer and isn't always necessary.
You can mark the needed dependencies to re-check them on update:
libraryDependencies ++= {
"org.specs2" %% "specs2" % "1.10-SNAPSHOT" % "test" changing()
}
Re-download a SNAPSHOT version of a dependency using SBT
The update command should help.
From the task's documentation:
Resolves and optionally retrieves dependencies, producing a report.
See Dependency Management Flow.
What's more important, SNAPSHOT dependencies are in their nature changing() so there's no need to add anything after ModuleID to mark them as such. Every update is supposed to resolve them against the repositories.
Perhaps update-classifiers is what you are looking for? Otherwise, try the tasks command to see what's available.