2

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?

Trevor Reid
  • 3,310
  • 4
  • 27
  • 46
pme
  • 14,156
  • 3
  • 52
  • 95

1 Answers1

2

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.

Sergey Romanovsky
  • 4,216
  • 4
  • 25
  • 27
  • thanks, it seems that Intellij shows the correct class but does not add the import when selected - might be a bug with Scala Scripts. – pme Jul 31 '19 at 05:03
  • 1
    try to explicitly tell IntelliJ to treat .sc files as ammonite: [intellj preferences screenshot](https://i.imgur.com/7A7xT0B.png) – Sergey Romanovsky Jul 31 '19 at 15:43