intellij 2020.1 sbt mainRunner configuration

让人想犯罪 __ 提交于 2020-04-30 06:33:26

问题


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?

Steps to Reproduce

  1. Create nice sbt project with idea.sbt already configured with mainRunner

sbt new tillrohrmann/flink-project.g8

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

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.
  1. Import project into intellij 2020.1

  2. Now what? I cannot find a "Use classpath of module" dropbox in intellij 2020.1.


回答1:


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

  1. Run | Edit Configurations...
  2. Click the plus button + to Add New Configuration
  3. Select Application
  4. Give it a name say WordCount
  5. Under Main Class specify Scala class with main method, say, org.example.WordCount
  6. Working directory should be the root of the project
  7. Set Use classpath of module to mainRunner
  8. JRE should be 1.8 or above

Note as an alternative to using mainRunner project you could also use root project but select the checkbox Include dependencies with "Provided" scope.



来源:https://stackoverflow.com/questions/61442430/intellij-2020-1-sbt-mainrunner-configuration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!