Importing sbt-based project to IntelliJ IDEA 13 (with sbt-idea, Scala 2.11 and sbt 0.12)

Just as in How to create SBT project with IntelliJ Idea? on StackOverflow I needed to import a sbt-managed project – scalaz – into IntelliJ IDEA.

With my configuration – Scala 2.11.0-M3 and sbt 0.12.4the answers to the question on StackOverflow were often misleading and hence the blog post.

jacek:~/oss/scalaz
$ sbt gen-idea
[info] Loading global plugins from /Users/jacek/.sbt/plugins
[info] Updating {file:/Users/jacek/.sbt/plugins/}default-b0cfcf...
[info] Resolving com.github.mpeltonen#sbt-idea;1.0.0 ...
[warn]      module not found: com.github.mpeltonen#sbt-idea;1.0.0
[warn] ==== typesafe-ivy-releases: tried
[warn]   http://repo.typesafe.com/typesafe/ivy-releases/com.github.mpeltonen/sbt-idea/scala_2.9.2/sbt_0.12/1.0.0/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn]   http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/com.github.mpeltonen/sbt-idea/scala_2.9.2/sbt_0.12/1.0.0/ivys/ivy.xml
[warn] ==== local: tried
[warn]   /Users/jacek/.ivy2/local/com.github.mpeltonen/sbt-idea/scala_2.9.2/sbt_0.12/1.0.0/ivys/ivy.xml
[warn] ==== sbt-idea-repo: tried
[warn]   http://mpeltonen.github.com/maven/com/github/mpeltonen/sbt-idea_2.9.2_0.12/1.0.0/sbt-idea-1.0.0.pom
[warn] ==== public: tried
[warn]   http://repo1.maven.org/maven2/com/github/mpeltonen/sbt-idea_2.9.2_0.12/1.0.0/sbt-idea-1.0.0.pom
[info] Resolving org.scala-sbt#precompiled-2_10_1;0.12.4 ...
[warn]      ::::::::::::::::::::::::::::::::::::::::::::::
[warn]      ::          UNRESOLVED DEPENDENCIES         ::
[warn]      ::::::::::::::::::::::::::::::::::::::::::::::
[warn]      :: com.github.mpeltonen#sbt-idea;1.0.0: not found
[warn]      ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn]      Note: Some unresolved dependencies have extra attributes.  Check that these dependencies exist with the requested attributes.
[warn]           com.github.mpeltonen:sbt-idea:1.0.0 (sbtVersion=0.12, scalaVersion=2.9.2)
[warn]
sbt.ResolveException: unresolved dependency: com.github.mpeltonen#sbt-idea;1.0.0: not found
...
[error] (*:update) sbt.ResolveException: unresolved dependency: com.github.mpeltonen#sbt-idea;1.0.0: not found
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? q

It didn’t take long to turn out that I should’ve read the website of the sbt-idea plugin first before looking for answers elsewhere. The system-wide build.sbt (in to ~/.sbt/plugins) configuration file should have a different repository instead and use the most recent stable (1.4.0) or 1.5.0-SNAPSHOT releases, too.

$ cat ~/.sbt/plugins/build.sbt
resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"

addSbtPlugin(dependency="com.github.mpeltonen" % "sbt-idea" % "1.5.0-SNAPSHOT")

With the change the command sbt gen-idea generated the necessary files with no errors.

jacek:~/oss/scalaz
$ sbt gen-idea
[info] Loading global plugins from /Users/jacek/.sbt/plugins
[info] Updating {file:/Users/jacek/.sbt/plugins/}default-b0cfcf...
[info] Resolving org.scala-sbt#precompiled-2_10_1;0.12.4 ...
[info] downloading http://oss.sonatype.org/content/repositories/snapshots/com/github/mpeltonen/sbt-idea_2.9.2_0.12/1.5.0-SNAPSHOT/sbt-idea-1.5.0-SNAPSHOT.jar ...
[info]      [SUCCESSFUL ] com.github.mpeltonen#sbt-idea;1.5.0-SNAPSHOT!sbt-idea.jar (2579ms)
[info] Done updating.
[info] Loading project definition from /Users/jacek/oss/scalaz/project
[info] Updating {file:/Users/jacek/oss/scalaz/project/}default-b1c5e5...
[info] Resolving org.scala-sbt#precompiled-2_10_1;0.12.4 ...
[info] Done updating.
[info] Set current project to scalaz (in build file:/Users/jacek/oss/scalaz/)
[info] Creating IDEA module for project 'xml'
...
[info] Created /Users/jacek/oss/scalaz/.idea_modules/typelevel.iml
[info] Created /Users/jacek/oss/scalaz/.idea_modules/scalaz-build.iml

In the latest version of IntelliJ IDEA 13 EAP 130.1179, codenamed Cardea, I could easily import the project pointing at the scalaz main directory where the project was cloned into.

scalaz-intellij-idea-sbt

The scalaz project set up IntelliJ IDEA-specific files to have them .gitignore‘d that I consider as a positive argument for the results of my experiments with sbt-idea.

jacek:~/oss/scalaz
$ git status
# On branch scalaz-seven
nothing to commit (working directory clean)
Be Sociable, Share!
This entry was posted in Languages, Tools.

Leave a Reply

%d bloggers like this: