我使用sbt-projectmatrix创建了2个sbt插件,customRow:
case class MatrixAxis(
idSuffix: String,
directorySuffix: String
) extends VirtualAxis.WeakAxis
// sbt
val oss = MatrixAxis("-oss", "oss")
val priv = MatrixAxis("-priv", "priv")
val scalaV = ???
lazy val devops = projectMatrix
.enablePlugins(SbtPlugin)
.settings(
pluginCrossBuild / sbtVersion := "1.3.13", // minimum sbt version
).customRow(
scalaVersions = Seq(scalaV),
axisValues = Seq(priv, VirtualAxis.jvm),
_.settings(...)
.customRow(
scalaVersions = Seq(scalaV),
axisValues = Seq(oss, VirtualAxis.jvm),
_.settings(...)
在sbt指南中,他们说:
sbt插件必须使用Scala 2.12进行编译。SBT本身是在其中编译的。通过不指定scalaVersion, sbt将默认为适合插件的Scala版本。
但我不知道如何创建一个customRow没有设置scalavertions ?
(如果我设置scalaVersions = Nil
,那么projectMatrix将不会为我创建任何项目)
sbt-projectmatrix需要静态地知道Scala版本,因为,除其他外,它使用它来构建项目的ID。因此,不幸的是,在scalaVersions
参数中,我们无法读取scalaVersion.value
的值来知道默认情况下sbt会选择什么。
我们可以做的是欺骗一点:首先,使用任何硬编码的2.12。在scalaVersions
中编写x版本(例如2.12.1)。然后,显式地覆盖scalaVersion := ...
,绕过sbt-projectmatrix将设置的2.12.1:
val oss = MatrixAxis("-oss", "oss")
val priv = MatrixAxis("-priv", "priv")
val scalaV = "2.12.1" // arbitrary 2.12.x version
lazy val devops = projectMatrix
.enablePlugins(SbtPlugin)
.settings(
pluginCrossBuild / sbtVersion := "1.3.13", // minimum sbt version
/* override with the default scalaVersion in the Global scope,
* which is sbt's choice, not impacted by sbt-projectmatrix
*/
scalaVersion := (Global / scalaVersion).value,
).customRow(
scalaVersions = Seq(scalaV),
axisValues = Seq(priv, VirtualAxis.jvm),
_.settings()
)
.customRow(
scalaVersions = Seq(scalaV),
axisValues = Seq(oss, VirtualAxis.jvm),
_.settings()
)