The inclusion of the project in the assembly depending on the setting value, for example. scalaVersion?

I have a Scala project that is divided into several subprojects:

lazy val core: Seq[ProjectReference] = Seq(common, json_scalaz7, json_scalaz)

I would like to make corelazy val conditional in the version of Scala that I am currently using, so I tried this:

lazy val core2: Seq[ProjectReference] = scalaVersion {
    case "2.11.0" => Seq(common, json_scalaz7)
    case _        => Seq(common, json_scalaz7, json_scalaz)
}

Simply put, I would like to exclude json_scalazfor Scala 2.11.0 (when the parameter value scalaVersion "2.11.0").

This, however, gives me the following compilation error:

[error] /home/diego/work/lift/framework/project/Build.scala:39: type mismatch;
[error]  found   : sbt.Project.Initialize[Seq[sbt.Project]]
[error]  required: Seq[sbt.ProjectReference]
[error]   lazy val core2: Seq[ProjectReference] = scalaVersion {
[error]                                                        ^
[error] one error found

Any idea how to solve this?

Update

I am using sbt version 0.12.4 This project is a Lift project that compiles with "2.10.0", "2.9.2", "2.9.1-1", "2.9.1" and now we are working on getting it to compile with 2.11.0. Therefore, creating a compilation of the entire task would be impractical, since it would take a very long time.

Update 2

I hope there is something like this:

lazy val scala_xml    = "org.scala-lang.modules"     %% "scala-xml"         % "1.0.1"
lazy val scala_parser = "org.scala-lang.modules"     %% "scala-parser-combinators" % "1.0.1"

...

lazy val common =
  coreProject("common")
    .settings(description := "Common Libraties and Utilities",
            libraryDependencies ++= Seq(slf4j_api, logback, slf4j_log4j12),
            libraryDependencies <++= scalaVersion {
              case "2.11.0" => Seq(scala_xml, scala_parser)
              case _ => Seq()
            }
  )

but for a list of projects

, Scala scala_xml scala_parser_combinator

+4
1

, json_scalaz Scala 2.11.0

sbt cross building, Cross-Building a Project. :

Scala crossScalaVersions. , .sbt:

crossScalaVersions := Seq("2.10.4", "2.11.0")

crossScalaVersions, +. :

> +compile

sbt , Aggregation. , compile test, json_scalaz.

lazy val withoutJsonScalaz = (project in file("without-json-scalaz")).
  .aggregate(liftProjects filterNot {_ == json_scalaz}: _*)

:

> ++2.11.0
> project withoutJsonScalaz
> test

, , - ScopeFilter. . , ScopeFilter scalaBinaryVersion.value. :

val coreProjects = settingKey[ScopeFilter]("my core projects")

val compileAll = taskKey[Seq[sbt.inc.Analysis]]("compile all")

coreProjects := {
  (scalaBinaryVersion.value) match {
    case "2.10" => ScopeFilter(inProjects(common, json_scalaz7, json_scalaz))
  }
}

compileAll := compileAllTask.value

lazy val compileAllTask = Def.taskDyn {
  val f = coreProjects.value
  (compile in Compile) all f
}

compileAll , +compile, - , sbt-unidoc.

+5

Source: https://habr.com/ru/post/1539141/


All Articles