Repository: com-lihaoyi/mill

Issue #2579: `[error] class type required but {some traits} found _root_.mill.define.Discover[build]`
Created: 2023-06-07T09:06:53Z
Issue
With Mill 0.11.0 and 0.11.0-M11 I see the following error message when using the scoverage contrib module:
[error] /tmp/out/mill-build/generateScriptSources.dest/millbuild/build.sc:14:32: class type required but mill.define.Module.BaseClass with ScoverageModule.this.ScoverageData found
[error]     _root_.mill.define.Discover[build]
[error]                                ^

Real World Projects

Initial discovered in lefou/mill-vcs-version#121
Also in lefou/mill-integrationtest#164

Minimized Reproduction
import $ivy.`com.lihaoyi::mill-contrib-scoverage:`
import mill._
import mill.contrib.scoverage.ScoverageModule
import mill.scalalib._

object core extends Cross[CoreCross]("2.13.11")
trait CoreCross extends CrossScalaModule with ScoverageModule {
  override def scoverageVersion = "2.0.10"
}
$ mill __.compile
Using mill version 0.11.0-M11
[build.sc] [41/49] compile 
[info] compiling 1 Scala source to /home/lefou/work/opensource/mill-vcs-version/repro-discover-issue/out/mill-build/compile.dest/classes ...
[error] /home/lefou/work/opensource/mill-vcs-version/repro-discover-issue/out/mill-build/generateScriptSources.dest/millbuild/build.sc:14:32: class type required but mill.define.Module.BaseClass with ScoverageModule.this.ScoverageData found
[error]     _root_.mill.define.Discover[build]
[error]                                ^
[error] one error found
1 targets failed
compile Compilation failed

$ cat out/mill-build/generateScriptSources.dest/millbuild/build.sc 

package millbuild
import _root_.mill._
import mill.runner.MillBuildRootModule
object MiscInfo_build{
  implicit val millBuildRootModuleInfo: _root_.mill.runner.MillBuildRootModule.Info = _root_.mill.runner.MillBuildRootModule.Info(
    Vector("/home/lefou/.cache/mill/download/0.11.0-M11", "/home/lefou/work/opensource/mill-vcs-version/repro-discover-issue/out/mill-launcher/0.11.0-M11.jar").map(_root_.os.Path(_)),
    _root_.os.Path("/home/lefou/work/opensource/mill-vcs-version/repro-discover-issue"),
    _root_.os.Path("/home/lefou/work/opensource/mill-vcs-version/repro-discover-issue"),
    _root_.scala.Seq()
  )
  implicit val millBaseModuleInfo: _root_.mill.main.RootModule.Info = _root_.mill.main.RootModule.Info(
    millBuildRootModuleInfo.projectRoot,
    _root_.mill.define.Discover[build]
  )
}
import MiscInfo_build.{millBuildRootModuleInfo, millBaseModuleInfo}
object build extends build
class build extends _root_.mill.main.RootModule{

//MILL_ORIGINAL_FILE_PATH=/home/lefou/work/opensource/mill-vcs-version/repro-discover-issue/build.sc
//MILL_USER_CODE_START_MARKER
import _root_._
import mill._
import mill.contrib.scoverage.ScoverageModule
import mill.scalalib._

object core extends Cross[CoreCross]("2.13.11")
trait CoreCross extends CrossScalaModule with ScoverageModule {
  override def scoverageVersion = "2.0.10"
}

Duplicate issue #2582: Exception in thread "MillServerActionRunner" `java.lang.ExceptionInInitializerError`
Created: 2023-06-07T19:05:06Z
Mill 0.11.0
Project: lefou/mill-vcs-version@d09eb3d
$ mill -j 0 __.compile + __.testCached
[build.sc] [#00] [22/49] cliImports 
Exception in thread "MillServerActionRunner" java.lang.ExceptionInInitializerError
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)
        at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1042)
        at java.base/jdk.internal.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
        at java.base/jdk.internal.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:186)
        at java.base/java.lang.reflect.Field.acquireFieldAccessor(Field.java:1105)
        at java.base/java.lang.reflect.Field.getFieldAccessor(Field.java:1086)
        at java.base/java.lang.reflect.Field.get(Field.java:418)
        at mill.runner.MillBuildBootstrap$.getRootModule(MillBuildBootstrap.scala:347)
        at mill.runner.MillBuildBootstrap.evaluateRec(MillBuildBootstrap.scala:106)
        at mill.runner.MillBuildBootstrap.evaluate(MillBuildBootstrap.scala:45)
        at mill.runner.MillMain$.$anonfun$main0$5(MillMain.scala:222)
        at mill.runner.Watching$.watchLoop(Watching.scala:27)
        at mill.runner.MillMain$.$anonfun$main0$1(MillMain.scala:210)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
        at scala.Console$.withErr(Console.scala:193)
        at mill.api.SystemStreams$.$anonfun$withStreams$2(SystemStreams.scala:56)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
        at scala.Console$.withOut(Console.scala:164)
        at mill.api.SystemStreams$.$anonfun$withStreams$1(SystemStreams.scala:55)
        at scala.util.DynamicVariable.withValue(DynamicVariable.scala:59)
        at scala.Console$.withIn(Console.scala:227)
        at mill.api.SystemStreams$.withStreams(SystemStreams.scala:54)
        at mill.runner.MillMain$.main0(MillMain.scala:80)
        at mill.runner.MillServerMain$.main0(MillServerMain.scala:83)
        at mill.runner.MillServerMain$.main0(MillServerMain.scala:35)
        at mill.runner.Server.$anonfun$handleRun$1(MillServerMain.scala:186)
        at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: java.lang.NullPointerException
        at millbuild.build.<init>(build.sc:18)
        at millbuild.build$.<init>(build.sc:18)
        at millbuild.build$.<clinit>(build.sc:18)
        ... 27 more

$ head -n 20 out/mill-build/generateScriptSources.dest/millbuild/build.sc
package millbuild

import _root_.mill.runner.MillBuildRootModule

object MiscInfo_build {
  implicit val millBuildRootModuleInfo: _root_.mill.runner.MillBuildRootModule.Info = _root_.mill.runner.MillBuildRootModule.Info(
    Vector("/home/lefou/.cache/mill/download/0.11.0", "/home/lefou/work/opensource/mill-vcs-version/out/mill-launcher/0.11.0.jar").map(_root_.os.Path(_)),
    _root_.os.Path("/home/lefou/work/opensource/mill-vcs-version"),
    _root_.os.Path("/home/lefou/work/opensource/mill-vcs-version"),
    _root_.scala.Seq()
  )
  implicit val millBaseModuleInfo: _root_.mill.main.RootModule.Info = _root_.mill.main.RootModule.Info(
    millBuildRootModuleInfo.projectRoot,
    _root_.mill.define.Discover[build]
  )
}
import MiscInfo_build.{millBuildRootModuleInfo, millBaseModuleInfo}
object build extends build
class build extends _root_.mill.main.RootModule {

Closing comment (2023-06-07T19:09:27Z): Probably related to #2579, so maybe an issue with Scala initialization order.