【问题标题】:IntelliJ + SBT plugin + multiproject setup = Unresolved dependency?IntelliJ + SBT 插件 + 多项目设置 = 未解决的依赖关系?
【发布时间】:2014-09-01 09:29:35
【问题描述】:

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

Parent
|-- Child A
|-- Child B

Parent/build.sbt中的light build定义如下:

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

如果我在文件夹Parent 中运行sbt gen-idea,则所有依赖项都会正确下载,并且会为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?

【问题讨论】:

  • 这是一个很老的问题,但对于遇到此问题的其他人,我的解决方案是使用resolvers in ThisBuild += "...." at "http...."(更多信息:stackoverflow.com/questions/18289766/…)

标签: scala intellij-idea sbt


【解决方案1】:

aggregate 命令的文档说它还打算为子项目执行所有命令。所以在Parent上执行compile也会在Project A和Project B上执行compile。

来自 sbt 文档

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

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

aggregate in gen-idea := false

这回答了您的问题,但我认为它不会使您的设置正常工作。我目前也在为多项目 sbt 苦苦挣扎。

【讨论】:

  • 谢谢,现在我从文档中获得了aggregate in 部分。 :) 不幸的是,您的建议不起作用:SBT 在aggregate in gen-idea := false 中告诉我error: not found: value gen...
  • 尝试aggregate in 是否适用于不同的任务,例如compile。也许有一些问题,因为gen-idea 是由插件提供的。那么这可能是一个错误。此外,我还设法让我的多项目设置与 gen-idea 一起工作,而不必摆弄聚合。
  • 你是如何让它工作的?能否请您发布您的配置,以便我可以将其与我的比较?
  • 顺便说一下,如果我指定aggregate in compile := false... :/
【解决方案2】:

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

我猜从技术上讲,您可以通过将解析器添加到每个子项目的 build.sbt 来解决它

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

但是,我不确定您为什么需要它,因为没有它它应该可以工作。当插件版本与 sbt 版本不同时,我也遇到了类似的问题(您可以使用 about 命令检查您的 sbt 版本)

【讨论】:

  • 感谢您的回答,但我希望在 SBT 中有更好的方法来解决这个问题。 :)
  • 正如我所说,我的 build.sbt 和多项目没有看到这个问题。你检查你使用的sbt版本和插件是一样的吗?
  • 嗯,这是来自sbt about 的输出: [info] 这是 sbt 0.11.1 [info] 当前项目是 {file:/Users/... [info] 当前项目是针对 Scala 2.9.1 [info] sbt、sbt 插件构建的,并且构建定义使用的是 Scala 2.9.1
  • 所以尝试使用匹配的插件。该 repo 的版本为 0.11.1 (mpeltonen.github.com/maven/com/github/mpeltonen/…),但您将其设置为获取 0.11 的版本。将 addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "0.11.0") 更改为 addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "0.11.1")
  • Errrr,要么我是瞎子,要么我很笨,要么我看起来不够好:我确实看到了 SBT 0.11.1 的版本,但它是插件的 0.11.0 版本。这就是你在说的,对吧? mpeltonen.github.com/maven/com/github/mpeltonen/…。所以用我目前的配置,如果我没记错的话,我实际上得到了正确的插件......
猜你喜欢
  • 2016-06-04
  • 2015-11-04
  • 1970-01-01
  • 2016-06-19
  • 2013-10-27
  • 1970-01-01
  • 2014-12-18
  • 2012-02-02
  • 2017-10-29
相关资源
最近更新 更多