Search code examples
scalaintellij-ideaammonitescala-script

Cannot Resolve Ammonite Main Methods in Intellij


I want to use @main like described here: https://ammonite.io/#ScriptArguments

@main
def all() = {
  ...
}

It cannot be resolved in Intellij. I couldn't find an import. I have added these dependencies:

libraryDependencies ++= Seq(
           "com.lihaoyi" %% "ammonite-ops" % "1.6.9",
           "com.lihaoyi" % "ammonite" % "1.6.9" cross CrossVersion.full
        )

Is there a way to achieve this?


Solution

  • Something like this should work:

    import ammonite.main.Router.main
    
    @main
    def all() = {
      print("hey")
    }
    
    all()
    

    Also, make sure you create Scala Worksheet (.sc) and not Scala Class (.scala) to allow IntelliJ to help you with ammonite imports.