How to create SBT project with IntelliJ Idea?

2019-01-07 01:29发布

I just got started with Scala/LiftWeb/Sbt developing, and I'd like to import a Sbt project in IntelliJ Idea. Actually, I managed to import my project in two different ways:

1) with Maven. I created a Maven project, and of top of that I created a Sbt project, which I then imported in IntelliJ. I could then easily start, stop the jetty server, and do other stuff. But that's not what I want. I want to do the same stuff, just Maven-free. That lead me to

2) with Eclipse. So, I created a new Sbt project (with a little script I wrote, configuring the Sbt project to be a WebProject). I used then the sbt-eclipsify plugin to 'convert' the project for Eclipse, which I then imported in IntelliJ (existing source -> eclipse). But the problems started here: I cannot get the IntelliJ Sbt plugin to work.

Can anyone help me with this?

7条回答
Summer. ? 凉城
2楼-- · 2019-01-07 02:05

For sbt 0.7

See the answer elsewhere on this page.

For sbt 0.10

Clone and build Ismael's sbt-idea:

git clone https://github.com/ijuma/sbt-idea.git
cd sbt-idea
git checkout sbt-0.10
./sbt package

Create an sbt plugin lib directory if you don't have one already

mkdir -p  ~/.sbt/plugins/lib

Copy the jar built in step one into here

cp sbt-idea/target/scala-2.8.1.final/*.jar ~/.sbt/plugins/lib

Restart or reload sbt, then you can run gen-idea (or gen-idea with-classifiers if you want sources and javadoc in intelliJ too)

Source: Tackers' suggestion on the message group.

In IntelliJ IDEA 13.x itself

You can open an SBT-based project in IDEA nowadays. It will create the necessary project and modules, and keep your dependencies up-to-date whenever you make changes to the build scripts.

查看更多
闹够了就滚
3楼-- · 2019-01-07 02:08

I just went through all this pain. I spend days trying to get an acceptable environment up and have come to the conclusion that ENSIME, SBT and JRebel are going to be my development environment for some time. Yes, it is going back to Emacs, but ENSIME turns it into a bit or an idea with refactoring, debugging support, navigation, etc. It's not nowhere near as good as Eclipse (Java), but unless the scala plugins work better it's the best we have.

Until the Scala development environments get up to snuff (Eclipse or IntelliJ) I'm not going to bother. They're just way too buggy.

See the discussion on the lift site.

http://groups.google.com/group/liftweb/browse_thread/thread/6e38ae7396575052#

Within that thread, there is a link to a HOWTO for IntelliJ, but although it kinda works, there are many issues that render it a little less that useful.

http://blog.morroni.com/2010/07/14/setup-intellij-9-for-lift-framework-development/comment-page-1/

查看更多
做自己的国王
4楼-- · 2019-01-07 02:12

The answers are old for 2014. In IntelliJ 13.x, the plugin Scala is ver 0.41.2 ( SBT is included).

My SBT version is 0.13.5 (terminal : sbt sbtVersion )

Go to the project's root folder and enter in the terminal

sbt idea

You will see two new hidden folders .idea and .idea_modules.

Then in IntelliJ, File > Open > select the project. It should open the project without any problem.

查看更多
闹够了就滚
5楼-- · 2019-01-07 02:17

For now I do this by hand. It is quite simple.

  1. Create the project with SBT
  2. Create a new IDEA Project with the same root path
  3. Create a module with the same root path
  4. Set src/main/scala as a src path on the module
  5. Set src/test/scala as a test path on the module
  6. Add scala-library.jar as a library
  7. Add lib (if it is present) as a jar directory within a module library
  8. Add lib_managed/compile (if it is present) as a jar directory within a module library
  9. Add lib_managed/test (if it is present) as a jar directory within a module library

That's it from memory. It would be better if it were automated, but it's no big deal as it is now.

One note of caution: The above approach doesn't work well with new-school sbt, i.e. versions 0.10 and newer, because it doesn't copy dependencies into lib_managed by default. You can add

retrieveManaged := true

to your build.sbt to make it copy the dependencies into lib_managed.

查看更多
Root(大扎)
6楼-- · 2019-01-07 02:17

Before you start creating your SBT project, make sure that the Scala plugin is downloaded and enabled in IntelliJ IDEA.

below link explains everything you need to know.

https://www.jetbrains.com/help/idea/2016.1/getting-started-with-sbt.html

查看更多
一夜七次
7楼-- · 2019-01-07 02:21

Tempus fugit and IntelliJ IDEA has become so much better these days. It's 2015 after all, isn't it?

Having said that, the latest version of IntelliJ IDEA 14.0.2 supports sbt projects out of the box with the Scala plugin. Just install the plugin and you should be able to open up Scala/sbt projects without much troubles.

Scala plugin under Plugins in Preferences

I'm using the Early Access version of the plugin which is 1.2.67.6.EAP as of the time of the writing.

With the plugin just point at a sbt project and IDEA is going to offer you a wizard to open that kind of project.

Import sbt project

About sbt-idea in sbt 0.12.4

For sbt 0.12.4 the system-wide plugin configuration file - ~/.sbt/plugins/build.sbt or PROJECT_DIR/project/plugins.sbt - should have the following lines:

resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"

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

Run sbt gen-idea to generate IDEA project files.

Read the sbt-idea plugin website for more up-to-date information. You may also find my blog entry Importing sbt-based project to IntelliJ IDEA 13 (with sbt-idea, Scala 2.11 and sbt 0.12) useful.

查看更多
登录 后发表回答