Reputation: 1447
I have a scala project which is build using sbt
. I want to import another project, which is also build using sbt
, and which is local on my machine.
My project structure looks like this:
my-project/build.sbt
my-project/external-project/
my-project/external-project/build.sbt
my-project/external-project/...
my-project/src/test
my-project/src/main
my-project/...
my build.sbt
looks like this:
lazy val root = Project("my-project", file("."))
.dependsOn(RootProject(file("./external-project/")))
.settings(
...
)
and this is what sbt "compile"
gives me
[warn] Binary version (2.11) for dependency org.scala-lang#scala-library;2.11.8
[warn] in my-project#my-project_2.10;0.1-SNAPSHOT differs from Scala binary version in project (2.10).
[info] Resolving externalproject#externalproject.10;0.1 ...
[warn] module not found: externalproject#externalproject.10;0.1
[warn] ==== local: tried
[warn] /home/martin/.ivy2/local/externalproject/externalproject_2.10/0.1/ivys/ivy.xml
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/externalproject/externalproject_2.10/0.1/externalproject_2.10-0.1.pom
[info] Resolving com.github.scopt#scopt_2.11;3.5.0 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: externalproject#externalproject_2.10;0.1: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Unresolved dependencies path:
[warn] externalproject:externalproject_2.10:0.1
[warn] +- my-project:my-project_2.10:0.1-SNAPSHOT
The external project is a git submodule. Neither projects uses Maven in any way.
I just want the files in my-project
to be able to import the scala files in external-project
, but I can't get it to work. What am I doing wrong? Do I need to restrcture my project?
Upvotes: 2
Views: 418
Reputation: 11308
You haven't specified the scalaVersion
for the current project, and it defaults to 2.10
. For your external project you have specified some scalaVersion
from the 2.11
series. You can see this in the artifact's name: externalproject_2.10
, where the _2.10
suffix stands for the Scala version the artifact was built with. Your external project doesn't provide an artifact for Scala 2.10, hence this error. Since Scala major releases are not binary compatible, you can't combine them dependency-wise.
To fix this, specify the Scala version in your build.sbt
: scalaVersion := "2.11.8"
.
Upvotes: 3