【问题标题】:intellij 2020.1 sbt mainRunner configurationintellij 2020.1 sbt mainRunner 配置
【发布时间】:2020-04-26 14:27:43
【问题描述】:

我正在尝试关注intructions 来设置 intellij scala 项目以使用 sbt。但是,我没有找到 intellij 2020.1 中描述的运行/配置。基于this post,我知道配置方式已经改变。但是,该帖子描述了如何使旧项目工作。我要为新项目做什么?

复制步骤

  1. 用已经配置 mainRunner 的 idea.sbt 创建漂亮的 sbt 项目

sbt new tillrohrmann/flink-project.g8

这包括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,上面写着:

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.
  1. 将项目导入 intellij 2020.1

  2. 现在呢?我在 intellij 2020.1 中找不到“使用模块的类路径”保管箱。

【问题讨论】:

    标签: intellij-idea sbt


    【解决方案1】:

    IntelliJ 的Use classpath of module 对应sbt 的子项目的classpath。要使用mainRunner 项目的类路径创建Run Configuration,请尝试

    1. Run | Edit Configurations...
    2. 单击加号按钮+Add New Configuration
    3. 选择Application
    4. 给它起个名字说WordCount
    5. Main Class 下使用main 方法指定Scala 类,例如org.example.WordCount
    6. Working directory 应该是项目的根
    7. Use classpath of module 设置为mainRunner
    8. JRE 应为 1.8 或更高版本

    请注意,作为使用 mainRunner 项目的替代方法,您也可以使用根项目,但选中复选框 Include dependencies with "Provided" scope

    【讨论】:

    • 我之前为此使用了包含“提供”范围选项的依赖项。我正在尝试了解有关 sbt 的更多信息。使用“提供”范围似乎最简单。有什么理由更喜欢使用 mainRunner?
    猜你喜欢
    • 2020-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    • 2015-11-17
    • 1970-01-01
    • 2018-08-03
    • 2020-09-05
    相关资源
    最近更新 更多