3

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?

Makoto
  • 104,088
  • 27
  • 192
  • 230
LeChe
  • 1,288
  • 14
  • 18
  • This is a pretty old question, but for anyone else that runs into this problem, my solution was using `resolvers in ThisBuild += "...." at "http...."` (further info: https://stackoverflow.com/questions/18289766/what-is-the-difference-between-thisbuild-and-global-scopes) – skofgar Jul 23 '18 at 05:31

2 Answers2

1

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.

ziggystar
  • 28,410
  • 9
  • 72
  • 124
  • Thanks, now I get the `aggregate in` part from the doc. :) Unfortunately, your suggestion does not work: SBT tells me `error: not found: value gen` in `aggregate in gen-idea := false`... – LeChe Nov 18 '11 at 15:13
  • Try if the `aggregate in` works with a different task like `compile`. Maybe there are some problems because `gen-idea` is provided by a plugin. Then this might be a bug. Also I have managed to get my multi-project setup working with `gen-idea` without having to fiddle with aggregation. – ziggystar Nov 18 '11 at 15:18
  • How did you get it to work? Could you please post your configuration so that I can compare it with mine? – LeChe Nov 19 '11 at 09:43
  • By the way, I do not get the error if I specify `aggregate in compile := false`... :/ – LeChe Nov 19 '11 at 09:47
0

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)

Arnon Rotem-Gal-Oz
  • 25,469
  • 3
  • 45
  • 68
  • Thanks for the answer, but I was hoping there was a nicer way of solving this in SBT. :) – LeChe Nov 18 '11 at 15:07
  • As I said I don't see this problem with my build.sbt and multi-projects. did you check the sbt version you use is the same as the plug-in? – Arnon Rotem-Gal-Oz Nov 18 '11 at 16:48
  • Well, this is the output from `sbt about`: [info] This is sbt 0.11.1 [info] The current project is {file:/Users/... [info] The current project is built against Scala 2.9.1 [info] sbt, sbt plugins, and build definitions are using Scala 2.9.1 – LeChe Nov 19 '11 at 09:42
  • so try to use the matching plug-in. The repo has a version for 0.11.1 (http://mpeltonen.github.com/maven/com/github/mpeltonen/sbt-idea_2.9.1_0.11.1/) but you set it to fetch the version for 0.11. change the addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "0.11.0") to addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "0.11.1") – Arnon Rotem-Gal-Oz Nov 19 '11 at 12:45
  • Errrr, either I am blind, stupid or not looking well enough: I do see a version for SBT `0.11.1`, but it's version `0.11.0` of the plugin. This is what you are talking about, right? http://mpeltonen.github.com/maven/com/github/mpeltonen/sbt-idea_2.9.1_0.11.1/0.11.0/. So with my current config, I am actually getting the correct plugin, if I am not mistaken... – LeChe Nov 19 '11 at 19:55
  • Using `addSbtPlugin("com.github.mpeltonen" %% "sbt-idea" % "0.11.0")` that is – LeChe Nov 19 '11 at 19:55
  • they have a 0.11.1-Snapshot (http://mpeltonen.github.com/maven/com/github/mpeltonen/sbt-idea_2.9.1_0.11.1/0.11.1-SNAPSHOT/).But I am not sure if they do support 0.11.1 correctly (I am using SBT 0.11 and the 0.11 version of the plugin and it works well) – Arnon Rotem-Gal-Oz Nov 19 '11 at 20:07
  • Not a big fan of SNAPSHOT dependencies. :) However, I did give it a try and it seems to be working now. Let's hope that there will be a release soon and that I won't run into problems later. Thanks for your help, I'll accept your answer. – LeChe Nov 19 '11 at 21:44