如何使用 IntelliJ Idea 创建 SBT 项目? [英] How to create SBT project with IntelliJ Idea?

查看:130
本文介绍了如何使用 IntelliJ Idea 创建 SBT 项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始使用 Scala/LiftWeb/Sbt 进行开发,我想在 IntelliJ Idea 中导入一个 Sbt 项目.实际上,我设法以两种不同的方式导入了我的项目:

1) 使用 Maven.我创建了一个 Maven 项目,最重要的是我创建了一个 Sbt 项目,然后我将其导入到 IntelliJ 中.然后我可以轻松地启动、停止码头服务器,并做其他事情.但这不是我想要的.我想做同样的事情,只是没有 Maven.这导致我

2) 使用 Eclipse.所以,我创建了一个新的 Sbt 项目(用我写的一个小脚本,将 Sbt 项目配置为一个 WebProject).然后我使用 sbt-eclipsify 插件来转换"Eclipse 的项目,然后我将其导入 IntelliJ(现有源 -> eclipse).但问题从这里开始:我无法让 IntelliJ Sbt 插件工作.

谁能帮我解决这个问题?

解决方案

创建项目的基本方式有 3 种——现代版本的 IntelliJ 可以开箱即用地导入 sbt 项目,否则你可以使用 sbt 插件生成IntelliJ 项目,或使用 IntelliJ Scala 插件创建 sbt 项目.使用这两种解决方案,基本功能开箱即用,一些复杂的构建可能会出现问题,因此请尝试其他工具,看看它是否在那里工作.

IntelliJ

如今,IntelliJ IDEA 变得更好了.当前版本 (14.0.2) 通过 Scala 插件支持开箱即用的 sbt 项目.只需安装插件,您应该可以毫无问题地打开 Scala/sbt 项目.

使用该插件,只需指向一个 sbt 项目,IDEA 就会为您提供一个向导来打开此类项目.

IntelliJ Scala 插件

IntelliJ 插件可以在这里找到http://confluence.jetbrains.com/display/SCA/Scala+Plugin+for+IntelliJ+IDEA 或者可以使用设置 -> 插件对话框从 IDE 中直接安装.之后你可以只做 File -> New Project -> Scala -> SBT based.IntelliJ 将生成基本的 build.sbt,下载必要的依赖项并打开项目.

SBT 插件

基于 sbt 文件生成创意项目的 Sbt 插件可以在这里找到:https://github.com/mpeltonen/sbt-idea

SBT 12.0+ &13.0+

只需将 addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.2") 添加到您的 build.sbt 中;不需要额外的解析器.

旧版本:

SBT 0.11+

创建以下行并将其添加到 ~/.sbt/plugins/build.sbtPROJECT_DIR/project/plugins.sbt

<块引用>

resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")

在 sbt 中使用 gen-idea 创建 IDEA 项目文件.

默认情况下,如果找到并将引用添加到 IDEA 项目文件中,则加载 sbt 和库依赖项的分类器(即源和 javadoc).如果您不想下载/引用它们,请使用命令 gen-idea no-classifiers no-sbt-classifiers.

<小时>

SBT 0.10.1(根据插件作者的说法,0.10.0 不会 工作!)

创建以下行并将其添加到 ~/.sbt/plugins/build.sbt:

resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"libraryDependencies += "com.github.mpeltonen" %% "sbt-idea" % "0.10.0"

使用 gen-idea sbt 任务创建 IDEA 项目文件.

默认情况下,如果找到并将引用添加到 IDEA 项目文件中,则加载 sbt 和库依赖项的分类器(即源和 javadoc).如果您不想下载/引用它们,请使用命令 gen-idea no-classifiers no-sbt-classifiers.

<小时>

SBT 0.7

要使用它,只需从您的 sbt shell 运行它,它就会将该插件用作外部程序:

 >* sbtIdeaRepo 在 http://mpeltonen.github.com/maven/>*idea 是 com.github.mpeltonen sbt-idea-processor 0.4.0...>更新...>主意...

您还可以根据需要在项目定义中添加特征:

import sbt._class MyProject(info: ProjectInfo) 使用 IdeaProject { 扩展 ParentProject(info)lazy val mySubProject = project("my-subproject", "my-subproject", new DefaultProject(_) with IdeaProject)//...}

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?

解决方案

There are three basic ways how to create a project - modern versions of IntelliJ can import sbt project out of the box, otherwise you can either use sbt plugin to generate IntelliJ project, or use IntelliJ Scala plugin to create sbt project. Basic features work out of the box using both solutions, some complex builds can have problems, so try other tools to see if it works there.

IntelliJ

IntelliJ IDEA has become so much better these days. The current version (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 any troubles.

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

IntelliJ Scala Plugin

IntelliJ plugin can be found here http://confluence.jetbrains.com/display/SCA/Scala+Plugin+for+IntelliJ+IDEA or can be installed directoly from within the IDE using Settings -> Plugins dialog. Afterwards one can just do File -> New Project -> Scala -> SBT based. IntelliJ will generate basic build.sbt, download necessary dependencies and open project.

SBT Plugin

Sbt plugin that generate an idea project based on the sbt files can be found here: https://github.com/mpeltonen/sbt-idea

SBT 12.0+ & 13.0+

Simply add addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.5.2") to your build.sbt; no additional resolvers are needed.

Older Versions:

SBT 0.11+

Create and add the following lines to ~/.sbt/plugins/build.sbt OR PROJECT_DIR/project/plugins.sbt

resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")

Use gen-idea in sbt to create IDEA project files.

By default, classifiers (i.e. sources and javadocs) of sbt and library dependencies are loaded if found and references added to IDEA project files. If you don't want to download/reference them, use command gen-idea no-classifiers no-sbt-classifiers.


SBT 0.10.1 (according to the plugin author, 0.10.0 won't work!)

Create and add the following lines to ~/.sbt/plugins/build.sbt:

resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"

libraryDependencies += "com.github.mpeltonen" %% "sbt-idea" % "0.10.0"

Use gen-idea sbt task to create IDEA project files.

By default, classifiers (i.e. sources and javadocs) of sbt and library dependencies are loaded if found and references added to IDEA project files. If you don't want to download/reference them, use command gen-idea no-classifiers no-sbt-classifiers.


SBT 0.7

To use it, simply run this from your sbt shell, it will use the plugin as an external program:

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

You can also add trait in your project definition, as you want:

import sbt._
class MyProject(info: ProjectInfo) extends ParentProject(info) with IdeaProject {
  lazy val mySubProject = project("my-subproject", "my-subproject", new DefaultProject(_) with IdeaProject)
   // ...
}

这篇关于如何使用 IntelliJ Idea 创建 SBT 项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆