简体   繁体   中英

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM