typelevel / sbt-typelevel

Let sbt work for you.
https://typelevel.org/sbt-typelevel/
Apache License 2.0
170 stars 48 forks source link

ThisBuild / crossScalaVersions results in error on project load #615

Open bpholt opened 1 year ago

bpholt commented 1 year ago

Using sbt-typelevel-settings v0.5.0-RC9, is it expected that using

ThisBuild / crossScalaVersions := Seq(Scala_2_12, Scala_2_13)

will result in this error on load?

java.util.NoSuchElementException
    at scala.collection.LinearSeqOptimized.last(LinearSeqOptimized.scala:150)
    at scala.collection.LinearSeqOptimized.last$(LinearSeqOptimized.scala:149)
    at scala.collection.immutable.List.last(List.scala:91)
    at org.typelevel.sbt.TypelevelSettingsPlugin$.$anonfun$globalSettings$3(TypelevelSettingsPlugin.scala:49)
    at scala.Function1.$anonfun$compose$1(Function1.scala:49)
    at sbt.internal.util.EvaluateSettings$MixedNode.evaluate0(INode.scala:229)
    at sbt.internal.util.EvaluateSettings$INode.evaluate(INode.scala:171)
    at sbt.internal.util.EvaluateSettings.$anonfun$submitEvaluate$1(INode.scala:88)
    at sbt.internal.util.EvaluateSettings.sbt$internal$util$EvaluateSettings$$run0(INode.scala:100)
    at sbt.internal.util.EvaluateSettings$$anon$3.run(INode.scala:95)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
[error] java.util.NoSuchElementException
[error] Use 'last' for the full log.
[warn] Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore? (default: r)

Removing ThisBuild / makes it work, but it's surprising that it matters:

crossScalaVersions := Seq(Scala_2_12, Scala_2_13)

This is the line in question:

https://github.com/typelevel/sbt-typelevel/blob/9309a656f0f3b97dfe2650fb6a8c99362a958fea/settings/src/main/scala/org/typelevel/sbt/TypelevelSettingsPlugin.scala#L49

armanbilge commented 1 year ago

Hmm, no, that seems odd. Any chance you can link to the build?

j-mie6 commented 1 year ago

INFO: my Scala cross versions are specified as:

inThisBuild(List(
   ...
   crossScalaVersions := Seq(Scala213, Scala212, Scala3),
   ...
)

Which I believe should be equivalent to what you had: it works fine on RC9.

bpholt commented 1 year ago

Any chance you can link to the build?

Unfortunately this is an internal library so I can't share the build. I'll see if I can minimize.

inThisBuild(List(
  ...
   crossScalaVersions := Seq(Scala213, Scala212, Scala3),
   ...
)

FWIW, I was under the impression that the inThisBuild macro has some subtle differences from the ThisBuild scope, so we've been moving things to use the scope directly. But in any event, in this build, I get the same NoSuchElementException using

inThisBuild(List(
  crossScalaVersions := Seq(Scala_2_12, Scala_2_13)
))

(albeit with a lot of other settings still set using the scope directly)

bpholt commented 1 year ago

@armanbilge I was able to minimize; check out this gist. tl;dr, it looks like it was caused by the root project explicitly setting crossScalaVersions := Seq.empty. (It did that to suppress publishing in the root project; I've since switched it to use the NoPublishPlugin instead.)