我创建了一个具有以下结构的新项目(模糊名称:):
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还会尝试在子项目projectA
和projectB
中运行该命令。这失败了以下内容:
[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
?
答案 0 :(得分:1)
aggregate
命令的文档说明它还要为子项目执行所有命令。因此,在compile
上执行Parent
也会在compile
和Project A
上执行Project B
。
聚合意味着在聚合项目上运行任务 也可以在聚合项目上运行它。用两个启动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版本)