Search code examples
scalaintellij-ideasbt

IntelliJ: Command Line is too Long. Shorten command line for... in SBT project


When I try to run my app, IntelliJ has just started to tell me

"Command Line is too Long. Shorten command line for my_app or also for Application default configuration."

the my_app is a blue link which leads to an "Edit Configuration" window, automatically selecting and highlighting a dropdown for class path shortener. I select the suggested options, but no change.

I have no idea what this means - I'm using Scala, so I'm using a simple object MyObj extends App which takes no parameters at all.

I have tried adding <property name="dynamic.classpath" value="true" /> to the workspace.xml as suggested by other similar questions, but to no avail.

I used to be able to run my programs in my project fine before. But what lengthens a command line? What is being put on the command line at all?


Solution

  • Found the fix, this is SBT specific. I believe what is happening is that the libaryDependencies one puts in their build.sbt file actually adds all the jars of those dependencies to the classpath used to run your program.

    To fix this, simply add

    lazy val scriptClasspath = Seq("*") (the lazy may be optional)

    to your build.sbt file. I placed mine above the root val with the library dependencies. Not sure if that's necessary, but shift it around if you're having trouble

    What this does, is upon running the program SBT will condense the "long" classpath built by those jars into a jar of its own, and just run that jar, which will kick off all of your dependencies and program.

    Check this out for the longer demonstration, as well as other answers