intellij 2020.1 sbt mainRunner配置 [英] intellij 2020.1 sbt mainRunner configuration
问题描述
我正在尝试遵循指令,用于设置与sbt一起使用的intellij scala项目.但是,我找不到intellij 2020.1中描述的运行/配置.基于这篇文章我了解此配置方式已更改.但是,该文章描述了如何使旧项目正常工作.我要为新项目做什么?
I am trying to follow the intructions for setting up intellij scala project to work with sbt. However, I am not finding the run/configuration described in intellij 2020.1. Based on this post I understand that the way this is configured has changed. However, that post describes how to make old project work. What do I do for new projects?
复制步骤
- 使用已经用mainRunner配置的idea.sbt创建一个不错的sbt项目
sbt new tillrohrmann/flink-project.g8
这包括idea.sbt
this includes idea.sbt
lazy val mainRunner = project.in(file("mainRunner")).dependsOn(RootProject(file("."))).settings(
// we set all provided dependencies to none, so that they are included in the classpath of mainRunner
libraryDependencies := (libraryDependencies in RootProject(file("."))).value.map{
module => module.configurations match {
case Some("provided") => module.withConfigurations(None)
case _ => module
}
}
)
它还带有一个README.md,内容为:
It also comes with a README.md that says:
You can also run your application from within IntelliJ: select the classpath of the 'mainRunner' module in the run/debug configurations.
Simply open 'Run -> Edit configurations...' and then select 'mainRunner' from the "Use classpath of module" dropbox.
-
将项目导入intellij 2020.1
Import project into intellij 2020.1
现在呢?我在intellij 2020.1中找不到使用模块的类路径"下拉框.
Now what? I cannot find a "Use classpath of module" dropbox in intellij 2020.1.
推荐答案
IntelliJ的Use classpath of module
对应于sbt的子项目的类路径.要使用mainRunner
项目的类路径创建Run Configuration
,请尝试
IntelliJ's Use classpath of module
corresponds to the classpath of sbt's sub-project. To create a Run Configuration
using the classpath of mainRunner
project try
-
Run | Edit Configurations...
- 单击加号按钮
+
到Add New Configuration
- 选择
Application
- 给它起个名字
WordCount
- 在
Main Class
下,使用main
方法指定Scala类,例如org.example.WordCount
-
Working directory
应该是项目的根源 - 将
Use classpath of module
设置为mainRunner
- JRE应该为1.8或更高
Run | Edit Configurations...
- Click the plus button
+
toAdd New Configuration
- Select
Application
- Give it a name say
WordCount
- Under
Main Class
specify Scala class withmain
method, say,org.example.WordCount
Working directory
should be the root of the project- Set
Use classpath of module
tomainRunner
- JRE should be 1.8 or above
注意,作为使用mainRunner
项目的替代方法,您也可以使用根项目,但选中复选框Include dependencies with "Provided" scope
.
Note as an alternative to using mainRunner
project you could also use root project but select the checkbox Include dependencies with "Provided" scope
.
这篇关于intellij 2020.1 sbt mainRunner配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!