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

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

问题描述

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

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)与Maven。我创建了一个Maven项目,最重要的是我创建了一个Sbt项目,然后我在IntelliJ中导入了该项目。然后我就可以轻松启动,停止Jetty服务器,并做其他事情。
但这不是我想要的。我想做同样的事情,只是Maven-free。
用Eclipse引导我

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)。所以,我创建了一个新的Sbt项目(我编写了一个小脚本,将Sbt项目配置为WebProject)。然后我使用sbt-eclipsify插件来转换Eclipse的项目,然后我在IntelliJ中导入(现有的源 - > eclipse)。
但问题从这里开始:我无法使用IntelliJ Sbt插件。

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.

任何人都可以帮我吗?

推荐答案

有三个如何创建项目的基本方法 - 现代版本的IntelliJ可以开箱即用导入sbt项目,否则你可以使用sbt插件生成IntelliJ项目,或使用IntelliJ Scala插件创建sbt项目。基本功能使用两种解决方案开箱即用,一些复杂的构建可能会有问题,所以尝试使用其他工具来查看它是否有效。

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 IDEA如今变得如此好看。当前版本(14.0.2)支持使用Scala插件开箱即用的sbt项目。只需安装插件,您就可以毫无困难地打开Scala / sbt项目。

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.

使用该插件,只需指向一个sbt项目,IDEA即可为您提供向导打开那种项目。

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插件可以在这里找到
http://confluence.jetbrains.com/display/SCA/Scala+Plugin+for+可以使用设置 - >插件对话框从IDE中直接安装IntelliJ + IDEA 。之后可以做文件 - >新项目 - > Scala - > SBT。 IntelliJ将生成基本的build.sbt,下载必要的依赖项并打开项目。

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文件生成构思项目的Sbt插件: a href =https://github.com/mpeltonen/sbt-idea =noreferrer> https://github.com/mpeltonen/sbt-idea

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 +

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

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

SBT 0.11 +

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

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")


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

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

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

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
(根据插件作者,0.10.0 不会工作!)

创建以下行并添加到〜/ .sbt / plugins / build.sbt:

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"

使用 gen-idea 用于创建IDEA项目文件的sbt任务。

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

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

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

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

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天全站免登陆