2

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.

Michael West
  • 1,636
  • 16
  • 23

1 Answers1

2

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

enter image description here

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

Mario Galic
  • 47,285
  • 6
  • 56
  • 98
  • I've used the Include dpendencies with "Provided" scope option before for this. I am trying to learn more about sbt. Using the "Provided" scope seems simplest. Is there any reason to prefer using mainRunner? – Michael West Apr 27 '20 at 12:35