Sbt 0.13.1 multi-project module not found when I change the default sbt library scala to scala 2.11.2

I am using sbt 0.13.1 to build two modules, and I am creating a /MyBuild.scala project to compile these two modules. MyBuild.scala:

import sbt._
import Keys._
object MyBuild extends Build {
    lazy val task = project.in(file("task"))
    lazy val root = project.in(file(".")) aggregate(task) dependsOn task
}

      

When I change the scala library to 2.11.2 by setting scalaHome . It will go to maven to load the task.jar and fail, it's very strange. Is this a sbt bug?

There is a github project url : test-sbt-0.13.1

+3


source to share


2 answers


I would recommend that you move the sources of the root project from root to subfolder (task2) and add them as aggregated ones. It will remove the aggregation and depending on the same project:

object MyBuild extends Build {
          lazy val task = project.in(file("task"))
          lazy val task2 = project.in(file("task2")) dependsOn task
          lazy val root = project.in(file(".")) aggregate(task, task2) 
}

      



This works for me, but it's strange that such a non-standard project structure works fine with the standard scalaHome. The problem seems to be how sbt resolves such a dependency as external.

PS This answer doesn't cover the whole story. See @ jjst's answer to clarify more.

0


source


This is because you have defined a custom one scalaVersion

in your main build.sbt file, which means it is only defined for the root project. The task project will use the default:

jjst@ws11:test-sbt-0.13.1$ sbt                                                                                                                
[...]
> projects
[info] In file:/home/users/jjost/dev/test-sbt-0.13.1/
[info]   * root
[info]     task
> show scalaVersion
[info] task/*:scalaVersion
[info]  2.10.4
[info] root/*:scalaVersion
[info]  2.11.2-local

      

As a consequence, artifacts generated by the task subproject will not be available for the root project in use.



You can fix this problem by making sure your projects are using the same one scalaVersion

. The easiest way to do this while keeping the same project structure is to share common options like the scala version for projects like this:

object MyBuild extends Build {
    val commonSettings = Seq(
      scalaVersion := "2.11.2-local",
      scalaHome := Some(file("/usr/local/scala-2.11.2/"))
    )

    lazy val task = (project.in(file("task"))).
    settings(commonSettings: _*)

    lazy val root = (project.in(file("."))).
    settings(commonSettings: _*).
    aggregate(task).
    dependsOn(task)
}

      

In practice, you may need to set the common parameters shared between projects in a dedicated file project/common.scala

, as recommended in Effective sbt .

+4


source







All Articles