IntelliJ + SBT插件+多项目设置=未解决的依赖?

时间:2011-11-17 10:03:34

标签: scala intellij-idea sbt

我创建了一个具有以下结构的新项目(模糊名称:):

Parent
|-- Child A
|-- Child B

Parent/build.sbt中的灯光构建定义如下:

name := "Parent"

scalaVersion := "2.9.1"

version := "1.0.0-SNAPSHOT"

Parent/project/Build.scala中的完整定义如下:

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"))
}

~/.sbt/plugins/build.sbt中,我有这个:

resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"

addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "0.11.0")

如果我在文件夹sbt gen-idea中运行Parent,则会正确下载所有依赖项,并为Parent正确创建项目定义。但是,sbt还会尝试在子项目projectAprojectB中运行该命令。这失败了以下内容:

[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

如果我将~/.sbt/plugins/build.sbt移至Parent/project/build.sbt,我会得到相同的结果。

如何阻止Parent的孩子执行gen-idea

2 个答案:

答案 0 :(得分:1)

aggregate命令的文档说明它还要为子项目执行所有命令。因此,在compile上执行Parent也会在compileProject A上执行Project B

来自sbt docs

  

聚合意味着在聚合项目上运行任务   也可以在聚合项目上运行它。用两个启动sbt   如示例中的子项目,并尝试编译。你应该看到   这三个项目都已编制完成。

进一步阅读它说你可以从聚合中排除某些任务,所以你想要

aggregate in gen-idea := false

这回答了你的问题,但我认为这不会使你的设置工作。我目前正在努力解决多项目问题。

答案 1 :(得分:0)

由于插件会为每个子项目创建单独的模块,因此我不会对子项目禁用gen-idea。

我想技术上你可以通过将解析器添加到每个子项目的build.sbt来解决它

resolvers += "sbt-idea-repo" at "http://mpeltonen.github.com/maven/"

然而,我不确定,为什么你需要它,因为它应该没有它。当插件版本与sbt版本不同时,我遇到了类似的问题(你可以通过about命令查看你的sbt版本)