Unresolved dependency when `dependOn` a local project - scala

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?

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".

Related

SBT 0.13.1 offline

I'm trying to understand the use of SBT 0.13.1 offline. My goal is to bring whatever is necesary to an offline environment on a USB stick. I thought that if the ivy cache was copied then SBT could pull everything it needs out of it, but that doesn't seem to be the case.
For example...
I'll start by deleting the .ivy2 folder, just to be sure. Now, while online I use the following build.sbt and project/plugins.sbt files to create my eclipse project. from SBT 0.13.1
build.sbt:
name := "TestProject"
version := "0.0.1"
scalaVersion := "2.10.3"
libraryDependencies ++= Seq(
"org.apache.commons" % "commons-math3" % "3.2",
"ch.qos.logback" % "logback-classic" % "1.1.1"
)
project/plugins.sbt:
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.4.0")
Sill on the same computiner I go offline, and now sbt clean eclipse gives lots of unresolved dependency errors. E.g.
[warn] Host repo1.maven.org not found. url=http://repo1.maven.org/maven2/org/scala-lang/scala-library/2.10.3/scala-library-2.10.3.pom
[info] You probably access the destination server through a proxy server that is not well configured.
[warn] module not found: org.scala-lang#scala-library;2.10.3
[warn] ==== local: tried
[warn] /home/user/.ivy2/local/org.scala-lang/scala-library/2.10.3/ivys/ivy.xml
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/org/scala-lang/scala-library/2.10.3/scala-library-2.10.3.pom
[info] Resolving ch.qos.logback#logback-classic;1.1.1 ...
[warn] Host repo1.maven.org not found. url=http://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.1.1/logback-classic-1.1.1.pom
[info] You probably access the destination server through a proxy server that is not well configured.
[warn] module not found: ch.qos.logback#logback-classic;1.1.1
[warn] ==== local: tried
[warn] /home/user/.ivy2/local/ch.qos.logback/logback-classic/1.1.1/ivys/ivy.xml
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/ch/qos/logback/logback-classic/1.1.1/logback-classic-1.1.1.pom
[info] Resolving org.scala-lang#scala-reflect;2.10.3 ...
[warn] Host repo1.maven.org not found. url=http://repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.10.3/scala-reflect-2.10.3.pom
[info] You probably access the destination server through a proxy server that is not well configured.
[warn] module not found: org.scala-lang#scala-reflect;2.10.3
[warn] ==== local: tried
[warn] /home/user/.ivy2/local/org.scala-lang/scala-reflect/2.10.3/ivys/ivy.xml
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.10.3/scala-reflect-2.10.3.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.scala-lang#scala-library;2.10.3: not found
[warn] :: ch.qos.logback#logback-classic;1.1.1: not found
[warn] :: org.scala-lang#scala-reflect;2.10.3: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
Is it really impossible to clean when working offline?
I notice that SBT is looking in .ivy2/local, but there is no such folder. Only '.ivy2/cache'.
Update:
Suggestion to add .ivy2/local didn't work. It gives many MalformedURLException
[warn] :: org.scala-lang#scala-library;2.10.3: ivy2 cache: unable to get resource for org/scala-lang#scala-library;2.10.3: res=/home/user/.ivy2/cache/org/scala-lang/scala-library/2.10.3/scala-library-2.10.3.pom: java.net.MalformedURLException: no protocol: /home/user/.ivy2/cache/org/scala-lang/scala-library/2.10.3/scala-library-2.10.3.pom
It's looking for a directory org/scala-lang etc, but thr directories in cache are of the form org.scala-lang
Update 2
It seems that the problem is caused with some interaction with logback. I've created a clearer version of my question here, and am accepting the answer that indicated that this 'should' run out of the box.
If you build the project online, then you can go offline after.
Basically, you'd just want to copy the ~/.ivy2 folder (and possibly ~/.sbt folder - unsure) into your environment from a location that has done the building and dependency resolution before.
Removing target/ in a project, then going offline, I can see that this does cause the resources to be resolved.
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 4 Scala sources to [...]
I'm not sure this will work but I guess you need to add another resolver in your Build.scala (or build.sbt) like this:
resolvers += "ivy2 cache" at "/home/user/.ivy2/cache"
Let me know if this works, I'm also curious about it.
Edit:
I tried it and sbt does look in your ivy2 cache, go in your build.sbt and add this line:
resolvers += Resolver.file("ivy2 cache", file("/path/to/your/ivy2/cache/"))(Resolver.ivyStylePatterns)
Now SBT should be looking in that directory too.

Unresolved dependencies for np 0.2.0 with SBT 0.13?

Scala 2.10.2 and SBT 0.13
I'm trying to use the np plugin and added the following lines to ../0.13/np.sbt:
seq(npSettings:_*)
(NpKeys.defaults in (Compile, NpKeys.np)) ~= {
_.copy(org="me.lessis", version="0.1.0-SNAPSHOT")
}
and this to <home-directory>/.sbt/plugins.sbt
addSbtPlugin("me.lessis" % "np" % "0.2.0")
resolvers += Resolver.url("sbt-plugin-releases",url("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns)
When I execute sbt run I am getting :
[info] Updating {file:/home/Projects/helloSbt/}default-310e5b...
[info] Resolving me.lessis#np;0.2.0 ...
[warn] module not found: me.lessis#np;0.2.0
[warn] ==== local: tried
[warn] /home/.ivy2/local/me.lessis/np/scala_2.10/sbt_0.12/0.2.0/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn] http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/me.lessis/np/scala_2.10/sbt_0.12/0.2.0/ivys/ivy.xml
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/me/lessis/np_2.10_0.12/0.2.0/np-0.2.0.pom
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: me.lessis#np;0.2.0: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] me.lessis:np:0.2.0 (sbtVersion=0.12, scalaVersion=2.10)
[warn]
[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: me.lessis#np;0.2.0: not found
[error] Total time: 3 s, completed Feb 6, 2014 9:23:17 AM
What am I doing wrong ?
For scala 2.10 you have to use sbt 0.13. I tried with sbt 0.13
Open in browser link:
http://dl.bintray.com/sbt/sbt-plugin-releases/me.lessis/np/scala_2.10/
There is only:
sbt_0.13/
For scala 2.9.2 you need to use sbt 0.12
==========================
Update:
Remove global configuration from $HOME/.sbt (plugins.sbt). or make or action from fresh user account (new user never used sbt)
Create empty directory test
Go to test
Create directory project
Go to project
Create plugins.sbt with content as above in question
Go to test directory
run sbt test or other command
see output - me.lessis#np;0.2.0 should be downloaded
Use .sbt/0.13/plugins/plugins.sbt (note the 0.13/plugins in the path) or even better for quick scan of the plugins installed, use .sbt/0.13/plugins/np.sbt so it's clear from the file name(s) about the plugins.
Please also note that from the question it appears that you're using SBT 0.12:
me.lessis:np:0.2.0 (sbtVersion=0.12, scalaVersion=2.10)
Add project/build.properties under helloSbt with the following line to have 0.13 be in use:
sbt.version=0.13.1

Installing ensime in existing project cannot resolve dependency

I started an android project in scala recently, I'm an emacs nerd, and I wanted to use ensime in emacs instead of IntelliJ. Per the installation instructions, and this post:
Installing Ensime for Scala Development on emacs: sbt.ResolveException: unresolved dependency: org.ensime#ensime-sbtt-cmd;0.12: not found
my ~/.sbt/plugins/plugins.sbt looks like this:
resolvers += "Sonatype releases" at "https://oss.sonatype.org/content/repositories/snapshots"
addSbtPlugin("org.ensime" % "ensime-sbt-cmd" % "0.1.2")
and my project's project/plugins.sbt looks like this:
addSbtPlugin("org.scala-sbt" % "sbt-android" % "0.7.1-SNAPSHOT")
(though I don't think that's related).
When I run sbt, the output looks like the following:
[info] Loading global plugins from /Users/jmiles/.sbt/plugins
[info] Updating {file:/Users/jmiles/.sbt/plugins/}default-bdeac8...
[info] Resolving org.ensime#ensime-sbt-cmd;0.1.2 ...
[warn] module not found: org.ensime#ensime-sbt-cmd;0.1.2
[warn] ==== typesafe-ivy-releases: tried
[warn] http://repo.typesafe.com/typesafe/ivy-releases/org.ensime/ensime-sbt-cmd/scala_2.9.2/sbt_0.12/0.1.2/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn] http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/org.ensime/ensime-sbt-cmd/scala_2.9.2/sbt_0.12/0.1.2/ivys/ivy.xml
[warn] ==== local: tried
[warn] /Users/jmiles/.ivy2/local/org.ensime/ensime-sbt-cmd/scala_2.9.2/sbt_0.12/0.1.2/ivys/ivy.xml
[warn] ==== Sonatype releases: tried
[warn] https://oss.sonatype.org/content/repositories/snapshots/org/ensime/ensime-sbt-cmd_2.9.2_0.12/0.1.2/ensime-sbt-cmd-0.1.2.pom
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/org/ensime/ensime-sbt-cmd_2.9.2_0.12/0.1.2/ensime-sbt-cmd-0.1.2.pom
[info] Resolving org.scala-sbt#precompiled-2_10_0-m7;0.12.1 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.ensime#ensime-sbt-cmd;0.1.2: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] org.ensime:ensime-sbt-cmd:0.1.2 (sbtVersion=0.12, scalaVersion=2.9.2)
[warn]
sbt.ResolveException: unresolved dependency: org.ensime#ensime-sbt-cmd;0.1.2: not found
at sbt.IvyActions$.sbt$IvyActions$$resolve(IvyActions.scala:214)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:122)
at sbt.IvyActions$$anonfun$update$1.apply(IvyActions.scala:121)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:114)
at sbt.IvySbt$Module$$anonfun$withModule$1.apply(Ivy.scala:114)
at sbt.IvySbt$$anonfun$withIvy$1.apply(Ivy.scala:102)
at sbt.IvySbt.liftedTree1$1(Ivy.scala:49)
(etc.)
Any help?
I get this all the time with dependencies. While I have no explanation for it, here are the common patterns that recur over and over.
Often, the code given by the plugin/library developer is wrong. When I go to their maven repository the version they have listed doesn't exist in the repository. I just update it to the right version and then boom it works. Also, for some reason some plugins work when I put them in plugins.sbt (the suggested place). While others only work if I stick them in project/build.sbt. It doesn't make sense, but as soon as I move it there it suddenly installs and runs. Combined dependency listings. If you are hacking stuff together and stick a dependency in both build.scala and build.sbt, it will throw a generic error that is completely unhelpful. Remove one or the other and suddenly it runs.
Also keep in mind that % causes a scala version to be appended to the name of it. whereas %% defines the name explicitly. Sometimes this causes errors when using % because it doesn't have a version available for that scala version. Go to the repository and enter the name of the package explicitly to fix this.
ensime 0.1.2 is only for sbt version 0.13.x. If this is a new project, you might consider using the current version of sbt. Typically you'd do this by creating project/build.properties that contains sbt.version=0.13.0

sbt and scct .... module not found: reaktor#sbt-scct;0.2-SNAPSHOT

scala is version 2.10.2 and sbt is 0.13.0
I am trying to setup scct for scala unit test code coverage so in build.sbt
I added
seq(ScctPlugin.instrumentSettings : _*)
and in project/plugins.sbt I added
resolvers += Classpaths.typesafeResolver
resolvers += "scct-github-repository" at "http://mtkopone.github.com/scct/maven-repo"
addSbtPlugin("reaktor" %% "sbt-scct" % "0.2-SNAPSHOT")
I get errors like ....
module not found: reaktor#sbt-scct;0.2-SNAPSHOT
Last message is
[warn] ==== scct-github-repository: tried
[warn] http://mtkopone.github.com/scct/maven-repo/reaktor/sbt-scct_2.10_0.13/0.2-SNAPSHOT/sbt-scct-0.2-SNAPSHOT.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: reaktor#sbt-scct;0.2-SNAPSHOT: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] reaktor:sbt-scct:0.2-SNAPSHOT (sbtVersion=0.13, scalaVersion=2.10)
I look in http://mtkopone.github.io/scct/maven-repo/reaktor/
and I see the one I seem to need is missing e.g. I see
sbt-scct_2.9.2_0.13/
scct_2.10/
and a bunch of others but no ... sbt-scct_2.10_0.13
Can you help ? (I am a sbt newbie)
SCCT has a new source code repository: https://github.com/SCCT/scct
As a result you can fetch a release version from maven central with addSbtPlugin("com.github.scct" %% "sbt-scct" % "0.2") in your plugins.sbt file.
My project to reproduce is on GitHub.
Update:
The repository has been relocated at https://github.com/sqality/scct
and you need addSbtPlugin("com.sqality.scct" % "sbt-scct" % "version") in your plugins.sbt file.
The original SCCT is inactive now.
Here are the two most active forks.
http://github.com/sqality
http://github.com/scoverage

IntelliJ + SBT plugin + multiproject setup = Unresolved dependency?

I created a new project with the following structure (obfuscated names :):
Parent
|-- Child A
|-- Child B
The light build definition in Parent/build.sbt is as follows:
name := "Parent"
scalaVersion := "2.9.1"
version := "1.0.0-SNAPSHOT"
The full definition in Parent/project/Build.scala is as follows:
import sbt._
import Keys._
object MyBuild extends Build {
lazy val root = Project(id = "Parent",
base = file(".")) aggregate(projectA, projectB)
lazy val projectA = Project(id = "Project A",
base = file("projectA"))
lazy val projectB = Project(id = "Project B",
base = file("projectB"))
}
In ~/.sbt/plugins/build.sbt, I have this:
resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"
addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "0.11.0")
If I run sbt gen-idea in the folder Parent, all dependencies are downloaded properly and the project definitions are created correctly for Parent. However, sbt also tries to run the command in the subprojects, projectA and projectB. This fails with the following:
[warn] module not found: com.github.mpeltonen#sbt-idea;0.11.0
[warn] ==== local: tried
[warn] /home/me/.ivy2/local/com.github.mpeltonen/sbt-idea/scala_2.9.1/sbt_0.11.1/0.11.0/ivys/ivy.xml
[warn] ==== Maven2 Local: tried
[warn] file:/home/me/.m2/repository/com/github/mpeltonen/sbt-idea_2.9.1_0.11.1/0.11.0/sbt-idea-0.11.0.pom
[warn] ==== typesafe-ivy-releases: tried
[warn] http://repo.typesafe.com/typesafe/ivy-releases/com.github.mpeltonen/sbt-idea/0.11.0/ivys/ivy.xml
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/com/github/mpeltonen/sbt-idea_2.9.1_0.11.1/0.11.0/sbt-idea-0.11.0.pom
[warn] ==== Scala-Tools Maven2 Repository: tried
[warn] http://scala-tools.org/repo-releases/com/github/mpeltonen/sbt-idea_2.9.1_0.11.1/0.11.0/sbt-idea-0.11.0.pom
[warn] ==== Scala-Tools Maven2 Snapshots Repository: tried
[warn] http://scala-tools.org/repo-snapshots/com/github/mpeltonen/sbt-idea_2.9.1_0.11.1/0.11.0/sbt-idea-0.11.0.pom
[info] Resolving commons-io#commons-io;2.0.1 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: com.github.mpeltonen#sbt-idea;0.11.0: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] com.github.mpeltonen:sbt-idea:0.11.0 (sbtVersion=0.11.1, scalaVersion=2.9.1)
[warn]
[error] {file:/opt/workspace/Parent/}ProjectA/*:update-sbt-classifiers: sbt.ResolveException: unresolved dependency: com.github.mpeltonen#sbt-idea;0.11.0: not found
[info] Created /opt/workspace/Parent/.idea_modules/project.iml
I get the same result if I move ~/.sbt/plugins/build.sbt to Parent/project/build.sbt.
How can I prevent the children of Parent to execute gen-idea?
The documentation of the aggregate command says that it is intended to execute all commands also for the sub projects. So executing compile on Parent will also execute compile on Project A and Project B.
From the sbt docs
Aggregation means that running a task on the aggregate project will
also run it on the aggregated projects. Start up sbt with two
subprojects as in the example, and try compile. You should see that
all three projects are compiled.
Reading further it says you can exclude certain tasks from the aggregation, so you want to do
aggregate in gen-idea := false
This answers your question, but I don't think it will make your setup work. I'm currently struggling with multi-project sbt, too.
I wouldn't go with disabling gen-idea for the sub-projects as the plug-in creates separate module for each sub-project.
I guessTechnically you can solve it by adding the resolver to each sub-project's build.sbt
resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"
I am not sure however, why you need that as it should work without that. I had similar problem when the plug-in version was not the same as the sbt version (you can check you sbt version with about command)