2024-01-20T04:43+01:00 (2024-01-20T18:58+01:00)

scala sbt shebang quick give-up

I wanted to look for more neat languages for XML processing. Stumbled upon the stackoverflow question 1613042 about right scripting languages for the job.

One of the answers, by geowa4, was Scala — "not a scripting language, but Scala is great for [working with XML natively]", linking to https://www.scala-lang.org/old/node/131 Also linking to "Scala XML Book" but link already dead, answer being 2009.

The JSX-esque syntax embeds appealed to me, and things were looking pretty promising. So I needed a way to script.

https://eed3si9n.com/scripting-with-scala/ presents an sbt shebang with -Dsbt.main.class=sbt.ScriptMain and -Dsbt.supershell=false, then having a /*** comment with libraryDependencies +=. The blog post also references Przemek Pokrywka's Truly standalone Scala scripts talk, which was about The Scripting Kit however, another solution.

The appropiate libraryDependencies entry for scala xml is explained in https://github.com/scala/scala-xml/wiki/Getting-started — "org.scala-lang.modules" %% "scala-xml" % "2.2.0"

But after all, even after setting supershell=true, over hours, my minimal example never finished building, the sbt shebang was just unresponsive.

#!/usr/bin/env sbt -Dsbt.main.class=sbt.ScriptMain -Dsbt.supershell=true -error

 libraryDependencies += "org.scala-lang.modules" %% "scala-xml" % "2.2.0"

import scala.xml.XML;
import scala.xml._;

val fname = "/home/mi/mibsite/log.xml";
val doc = XML.loadFile(fname);

Turned out it was lacking a flag to /usr/bin/env to split the concatenated arguments from a shebang, but even then it just failed quietly.