Using sbt as a library - scala

sbt has a bunch of nice utils in (e.g.) sbt IO - I'd like to use these in my app. What are the artifact group/names/versions I should be referencing? (This is nearly impossible to Google for...) I looked in scala-tools.org but I could only find 2.7-compatible releases (and I'm building a 2.9 project) - am I out of luck? (For now I might try copying the relevant sources over into my project, if they're easy enough to tease apart and to port to 2.9.)

The groupId is org.scala-sbt as can be seen from https://github.com/harrah/xsbt/blob/0.12.1/project/Sbt.scala but apparently the latest artifacts are not available in a Maven repository. It might be best to build sbt yourself and install it into your local repository, or to just copy the source files into your project. The latest version of sbt (version 0.11) appears to use Scala 2.9.

Related

Why it took so long to download sbt dependencies when I create a scala project in intellij idea?

I am new to scala, when I create a scala project in intellij it took really so long to download all the jar files. I have installed the scala plugin for idea IDE. Could anyone please tell me what should I do to get on the right track? Thanks very much.
Since the scala language is really a library on top of the JVM, creating a scala project for the first time requires the download of the specified scala version from a maven repository (usually this is at least the compiler and library, which for 2.10 comes to ~20MB). This will happen the first time, even if you've installed that same version of scala on your machine outside of sbt.
Once you go through this the first time, though, the next project you create--whether via sbt on the command line or via an IntelliJ sbt project--will pull these dependencies from your local ivy cache instead.
However, should you change the language version in your project, it will once again have to download the full language dependencies for that version.
In the screenshot it try to download the source files of one of of the dependencies. That mean it will try to download not only the compiled jars, but also it's source and docs.
only after downloading all of them, the project will be ready.
Disable to downloading of the sources and docs, and it will be much faster. How to disable it depends on how you create the project. (eg if you create sbt project, make sure to uncheck the "download sources and docs" in the creation/import wizard)

How to use existing Intellij projects as a I move forward with SBT?

Novice SBT question - Now that I've started with some basic SBT tutorials, I'd like to start using SBT build files (within Intellij) a lot more often. However, there's a couple of problems with this :
1) Existing projects that I currently publish to a jar, and later import into other projects... how do I publish this jar file to my local repository? SBT publish-local doesn't seem to fit my situation, because the project was made in Intellij and is not (yet) an SBT project.
2) Suppose I do convert the project to an SBT build setup (and then import it into Intellij).. how do I configure Intellij to to publish-local (update) each time I build the project? I do not see many configurable settings around SBT within the new Intellij SBT support.
Using Intellij 13 and SBT 0.13.1
Thanks!
to get you started up quickly on using SBT to drive Idea, have a look at my template project called skeleton
It supports most of the basic tasks you'd want to do.
To publish to your repository, use the publish task.
hope that helps!
For publishing, you simply use the publish action:
To specify the repository, assign a repository to publishTo and optionally set the publishing style. For example, to upload to Nexus:
publishTo := Some("Sonatype Snapshots Nexus" at "https://oss.sonatype.org/content/repositories/snapshots")
As for your second question, despite being a JetBrains fanboy, I have found SBT integration quite disappointing. For one thing, as the JetBrains documentation states itself, you need two plugins: their plugin and sbt-idea. You use sbt-idea to synchronize the IDEA module structure with the SBT build, and you use JetBrains' idea-sbt-plugin to execute SBT tasks in the "Before Launch" action in Run Configurations.
It sounds like you want to do an "install" on every build, so "Before Launch" action support isn't useful. I would suggest writing your own custom SBT task to install on build and using the Command Line Tools Console to execute that task with SBT as if from the command line. I know; that indirection is annoying.
Bear in mind one more thing. I have found numerous bugs with idea-sbt-plugin. At least on Mac. JetBrains told me the next version will be much better, and you can see for yourself with the next EAP version.
I certainly welcome others who have managed to have more success than I have to chime in.

Using a library from github not existing in mvn repository

There is a Scala library for redis https://github.com/debasishg/scala-redis. It doesn't exist in mvnrepository.com. It's even not written at github how I must use it (add it as a dependency).
So how do I do that, how do I do add it as a dependency in my project?
If you look at the scala-redis' SBT Project file, it's recorded as redisclient. Searching for the same in maven sonatype, I get this result. Assuming you're using scala-2.10 - if not, you can see the list of released builds for other versions here.

How to proxy a static snapshot of scala 2.10.3

Scala 2.10.3 has a bug fix my team needs; but, I don't want to subject my group to a constantly changing version (using 2.10.3-SNAPSHOT). How can I download the latest snapshot, publish it to my local nexus (say 2.10.3-FOO) and have sbt use it? I'm familiar with proxy-ing and did get sbt to use our nexus repository to download the renamed scala-lang, scala-compiler. However, it never downloads scala-reflect and bombs out. What am I missing?
I found that pulling down scala.git and publishing a local build to our nexus repo using the ant tasks provided allowed me to accomplish what I was after. In terms of sbt, the documented way of using a proxy repo (-Dsbt.override.build.repos=true, using the repositories file) worked well.

How to set up a local proxy repository for SBT?

I have near zero knowledge of Maven/Ivy but know that these technologies are behind SBT's ability to download and manage libraries automatically.
When I was trying to generate an IntelliJ Idea project from SBT it (Idea or the generator plug-in) has failed to find cached libraries stored in the common Ivy 2 cache. I've solved the problem by setting up the SBT project to use the old scheme storing downloaded libraries under the project directory. Another project of mine uses old SBT version which does it this way by default. In both cases I use clean command to remove library binaries before backing up and update after to download all the libraries again. Which means I download the same library files many times.
The question is how to set up a local repository to cache the libraries so that SBT update will download the libraries from the local cache if available? Would be nice to use the existing ~/.ivy2/cache directory for the cache if possible.
I tend to believe this is probably fairly simple when you have at least basic Ivy 2 knowledge.
Ivan, this may help.
sbt
> deliver-local
[info] delivering ivy file to /.../target/scala-2.9.1/ivy-1.0.xml
Then, you'll need to find IntelliJ equivalent steps, but in Eclipse you configure the build path with an additional library, "IvyDE Managed Dependencies" offered by the IvyDE plugin
1) browse to the target/scala-version/ivy-1.0.xml file
2) select desired configurations (compile, runtime, test, provided, etc.)
Now you have an ivy representation of your sbt configuration.
This works wonderfully with one annoying exception: on "sbt clean", ivy config file gets blown away and you have to repeat the above. Eclipse project clean preserves ivy config, btw.
Keep posted if this approach can be applied to IntelliJ