IntelliJ + SBT plugin + multiproject setup = Unresolved dependency? - scala

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)

Related

Unresolved dependency when `dependOn` a local project

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

sbt can't find local repository defined by Resolver.file()

I use
name := "sbt-publish-test"
version := "0.1-SNAPSHOT"
publishTo := Some(Resolver.file("sbt-repo", file("/home/pishen/sbt-repo")))
and sbt publish to publish my project into the directory.
Now in another project, I want to resolve the project I just published. I use
resolvers += "my-repo" at "file:///home/pishen/sbt-repo"
libraryDependencies += "default" %% "sbt-publish-test" % "0.1-SNAPSHOT"
and is able to resolve the project without any error. The result of show resolvers is:
> show resolvers
[info] List(my-repo: file:///home/pishen/sbt-repo)
But, when I use
resolvers += Resolver.file("my-repo", file("/home/pishen/sbt-repo"))
libraryDependencies += "default" %% "sbt-publish-test" % "0.1-SNAPSHOT"
The result of show resolvers become:
> show resolvers
[info] List(FileRepository(my-repo,FileConfiguration(true,None),Patterns(ivyPatterns=List(), artifactPatterns=List(/home/pishen/sbt-repo/[organisation]/[module](_[scalaVersion])(_[sbtVersion])/[revision]/[artifact]-[revision](-[classifier]).[ext]), isMavenCompatible=true, descriptorOptional=false, skipConsistencyCheck=false)))
and sbt said that it can't resolve the dependency when I typed sbt update:
[warn] module not found: default#sbt-publish-test_2.10;0.1-SNAPSHOT
[warn] ==== local: tried
[warn] /home/pishen/.ivy2/local/default/sbt-publish-test_2.10/0.1-SNAPSHOT/ivys/ivy.xml
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/default/sbt-publish-test_2.10/0.1-SNAPSHOT/sbt-publish-test_2.10-0.1-SNAPSHOT.pom
[warn] ==== my-repo: tried
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: default#sbt-publish-test_2.10;0.1-SNAPSHOT: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
Is this a bug? Or am I use Resolver.file() in a wrong way? What's the difference between "name" at "url" and Resolver.file()? I'm using sbt 0.13.7.
My suspicion is that when you use Resolver.file in that context, it's intended to be more of a "builder" creator, expecting subsequent method calls to fill in additional configuration information that have different defaults when using the "name" at "uri" syntax.
The sbt ScalaDoc for Resolver.file.apply alludes to something along these lines:
Constructs a file resolver with the given name. The patterns to use must be explicitly specified using the ivys or artifacts methods on the constructed resolver object.
When I've done something similar to what you're doing, I start with a File and use its API to convert it into the URI form:
resolvers += "my-repo" at file("/home/pishen/sbt-repo").toURI.toASCIIString

Why can't sbt resolve OpenIMAJ dependency?

Here is the build.sbt I use in a project:
name := "FaceReg"
version := "1.0"
libraryDependencies += "org.openimaj" % "image-processing" % "1.2.1"
While updateing the project, sbt reports UNRESOLVED DEPENDENCIES:
[info] Resolving org.openimaj#image-processing;1.2.1 ...
[warn] module not found: org.openimaj#image-processing;1.2.1
[warn] ==== local: tried
[warn] /Users/jacek/.ivy2/local/org.openimaj/image-processing/1.2.1/ivys/ivy.xml
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/org/openimaj/image-processing/1.2.1/image-processing-1.2.1.pom
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.openimaj#image-processing;1.2.1: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: org.openimaj#image-processing;1.2.1: not found
What could be issue? How to solve it?
OpenImaj has its own repository and does not publish artifacts to the maven central (that's one of the few repositories consulted by sbt by default).
Add the following resolvers to build.sbt to have the dependency resolved properly and you will be fine:
resolvers += "OpenIMAJ maven releases repository" at "http://maven.openimaj.org"
resolvers += "OpenIMAJ maven snapshots repository" at "http://snapshots.openimaj.org"
Also, make sure you use only % in artifact, not %% because right now it looks like you're targeting specific Scala version in dependency and it's not what you would want for OpenImaj.

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