Mill:如何为 RootModule 构建交叉构建?

问题描述 投票:0回答:1

我有 Mill 项目,目前是为 Scala 3 构建的。

我正在准备 Scala 2.13 的交叉构建。

目前我有这个

build.sc

import mill._, scalalib._
import publish._

// qw is my project name
object qw extends Cross[QwModule]("2.13.11", "3.3.0") {
  def defaultCrossSegments = Seq("3.3.0")
}
trait QwModule
    extends Cross.Module[String]
    with RootModule
    with ScalaModule
    with PublishModule
    with Cross.Module[String] {
  def scalaVersion = crossValue
  // ...
}

但是这不能编译:

% mill 'qw[3.3.0].compile'                                                                                    [39/1074]
[build.sc] [43/52] compile                                                                                             
[info] compiling 1 Scala source to /home/windymelt/src/github.com/windymelt/qw.scala/out/mill-build/compile.dest/classe
s ...                                                                                                                  
[info] done compiling                                                                                                  
[build.sc] [52/52] methodCodeHashSignatures              
Exception in thread "MillServerActionRunner" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length
 0                                                                                                                     
        at scala.collection.immutable.ArraySeq$ofRef.apply(ArraySeq.scala:331)
        at scala.collection.IndexedSeqOps.head(IndexedSeq.scala:94)
        at scala.collection.IndexedSeqOps.head$(IndexedSeq.scala:94)
        at scala.collection.immutable.ArraySeq.head(ArraySeq.scala:35)
        at mill.resolve.Resolve$.mill$resolve$Resolve$$instantiateTarget(Resolve.scala:92)                            
        at mill.resolve.Resolve$Tasks$.$anonfun$handleResolved$3(Resolve.scala:46)
        at scala.util.Either.flatMap(Either.scala:352)
        at mill.resolve.Resolve$Tasks$.$anonfun$handleResolved$2(Resolve.scala:46)
        at scala.collection.immutable.List.map(List.scala:246)
        at scala.collection.immutable.List.map(List.scala:79)
        at mill.resolve.Resolve$Tasks$.handleResolved(Resolve.scala:42)
        at mill.resolve.Resolve.$anonfun$resolveNonEmptyAndHandle$3(Resolve.scala:241)
        at scala.util.Either.flatMap(Either.scala:352)
        at mill.resolve.Resolve.resolveNonEmptyAndHandle(Resolve.scala:241)
        at mill.resolve.Resolve.resolveNonEmptyAndHandle$(Resolve.scala:223)
        at mill.resolve.Resolve$Tasks$.resolveNonEmptyAndHandle(Resolve.scala:34)
        at mill.resolve.Resolve.$anonfun$resolve0$4(Resolve.scala:207)
        at scala.util.Either.map(Either.scala:382)
        at mill.resolve.Resolve.$anonfun$resolve0$3(Resolve.scala:206)
        at scala.collection.immutable.List.map(List.scala:246)
        at scala.collection.immutable.List.map(List.scala:79)
        at mill.resolve.Resolve.$anonfun$resolve0$2(Resolve.scala:205)
...

如何使用跨 scala 版本控制构建 RootModule?

scala build-tools mill
1个回答
0
投票

A

RootModule
始终需要是单例顶级模块。

解决您的特定问题的快速方法是从您的

extends RootModule
特征中删除
QwModule
,您的 Mill 命令应该按预期工作。

更多解释

如果没有显式的

RootModule
,Mill 使用内置的根模块,并且您在
build.sc
中定义的所有模块都将成为它的子模块。因此,从 Mill CLI 运行它们时,您需要指定它们的完整分段名称或使用一些模式。

因此,要编译顶级 Scala 模块

qw
,您的 Mill 命令是
mill qw.compile
。 然而,如果您将
qw
模块设为
RootModule
,则用于编译它的 Mill 命令是
mill compile

RootModule
添加到
Cross
模块违反了这两个要求:

  1. 它不再是顶级模块,因为

    Cross.Module
    实例是其持有的
    Cross
    模块的子模块。

  2. 它不再是单例,因为你有两个,每个

    crossValue
    一个。

还有其他一些思考

我想知道你是如何得到这个错误的(

java.lang.ArrayIndexOutOfBoundsException
)。相反,您应该至少看到一个编译错误,因为您发布的
build.sc
无法编译,并且
RootModule
是一个抽象类,因此它不能与
with
关键字混合。

© www.soinside.com 2019 - 2024. All rights reserved.