2

I manage my project using Maven and SBT at same time. The reasons for this are:

  1. Intellij IDEA cannot import SBT project.(idea-sbt plugin doesn't work very well)
  2. I don't know how can get sources and javadocs from SBT.(I'd like to see any answers about this)

The problem is I don't know how to let Maven download SBT dependency. I search through maven repository and couldn't find anything about sbt. I wanna use Maven or SBT to manage all the jars in my project.

Sawyer
  • 15,581
  • 27
  • 88
  • 124

2 Answers2

5
  • If you put a pom.xml to the root of your project, it will be recognized by SBT. When you specify no managed dependencies in the project definition, SBT relies on Maven dependencies.

    As it said in SBT doumentation,

sbt performs this dependency handling when the update action is executed. By default, sbt does not update your dependencies before every compilation, but only does so when you execute update. sbt supports three ways of specifying these dependencies:

* Declarations in your project definition
* Maven POM files
* Ivy configuration and settings files
  • Maven knows nothing about SBT as of now (at least, I've not heard about any plugins so far), so, the best you can do to manage your project both in Maven and SBT, is to generate POMs by SBT. See SBT to Maven Converter for more details.
Community
  • 1
  • 1
Vasil Remeniuk
  • 20,519
  • 6
  • 71
  • 81
  • Yes, but when imported into IDEA, it claims not found SBT.jar,because it does exist in maven, what I ask is how to add the sbt dependency into pom.xml. – Sawyer Mar 13 '11 at 07:48
  • Why do you need your project to depend on sbt.jar (build-time, meta-level dependency)? It's required (in the most cases) only by project definition that is, in its turn, useful (and, on a standard setup, visible) only for SBT. – Vasil Remeniuk Mar 13 '11 at 07:57
  • Because you define sbt project definition using scala source and IDE will try to parse and compile that file. If you don't have a valid sbt library in your classpath, it will report compilation error, and I don't wanna point to that jar in my hard drive. – Sawyer Mar 13 '11 at 08:08
  • It's indeed Scala source, but unless you place it under src/{main, test}/scala, Maven should ignore it (thought IDE will complain on missing dependencies, which I personally ignore in Netbeans), and compile the project just fine. What you can do is to try adding sbt.jar to the classpath of your IDE. – Vasil Remeniuk Mar 13 '11 at 08:22
5

idea-sbt plugin works great for me with IDEA 10 - all it's really intended to do is open an SBT shell within the IDE and it does that well enough.

A plugin you should look into if you're interested in getting the Maven out of your build is sbt-idea plugin ( https://github.com/mpeltonen/sbt-idea ). This is a great plugin that generates IDEA files from an SBT project. It couldn't be easier to use. At an SBT prompt, run the following commands:

*sbtIdeaRepo at http://mpeltonen.github.com/maven/
*idea is com.github.mpeltonen sbt-idea-processor 0.3.0
update
idea

Note the asterisks - they should be included.

At this point, you can open your project in IDEA. It won't complain about the SBT dependencies. Any time you add new dependencies to your project file, simply run the 'idea' command again to tell IDEA about it. I do that in the SBT window provided by idea-sbt.

As far as getting sources and docs with dependencies, you can do something like this (from the SBT docs):

val sc = "org.scalacheck" % "scalacheck" % "1.5" withSources()

There is a corresponding withJavadoc() method. Hope that helps.

Janx
  • 3,285
  • 3
  • 19
  • 24