问题
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
- 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.
Import project into intellij 2020.1
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
Run | Edit Configurations...- Click the plus button
+toAdd New Configuration - Select
Application - Give it a name say
WordCount - Under
Main Classspecify Scala class withmainmethod, say,org.example.WordCount Working directoryshould be the root of the project- Set
Use classpath of moduletomainRunner - 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