mill icon indicating copy to clipboard operation
mill copied to clipboard

Main method is not runnable with `mill-bsp` and Scala 2 from Metals

Open arturaz opened this issue 6 months ago • 1 comments

If you have code like this:

object Main {
  def main(args: Array[String]): Unit = {
    println("Hello world!")
  }
}

Code lenses that allow running this appear in Metals if you're using Scala 3.

Image

But does not if you're using Scala 2.13.16:

Image

Image

The BSP trace shows the main classes:

[Trace - 11:54:04 AM] Received response 'buildTarget/scalaMainClasses - (8)' in 67ms
Result: {
  "items": [
    {
      "target": {
        "uri": "file:///home/arturaz/work/mill-resources-test/foo"
      },
      "classes": [
        {
          "class": "Main",
          "arguments": [],
          "jvmOptions": [],
          "environmentVariables": [
            "DOGGIES\u003dmain"
          ]
        }
      ]
    },
    {
      "target": {
        "uri": "file:///home/arturaz/work/mill-resources-test/foo/test"
      },
      "classes": [
        {
          "class": "TestMain",
          "arguments": [],
          "jvmOptions": [],
          "environmentVariables": [
            "OTHER_FILES_DIR\u003d/home/arturaz/work/mill-resources-test/foo/test/other-files",
            "DOGGIES\u003dtests"
          ]
        }
      ]
    },
    {
      "target": {
        "uri": "file:///home/arturaz/work/mill-resources-test/mill-build"
      },
      "classes": []
    }
  ]
}
Error: null

Reproduction case: https://github.com/arturaz/mill-issue-repro-5230

arturaz avatar May 30 '25 08:05 arturaz

Tagging as upstream for now.

@arturaz Could you re-test with Mill 1.0.0-RC1 again?

Also, your repro project is on Mill 0.12.14 but the screenshot of Metals Doctor shows some 1.0.0-M1-xxx version. Is this issue present in both Mill versions?

lefou avatar Jun 01 '25 09:06 lefou

Not sure about Scala 2, but it seems to work in Scala 3, so will close this

Image

lihaoyi avatar Nov 06 '25 11:11 lihaoyi