我有一个使用宏的 scala 项目,它基本上遵循此处描述的确切方法(http://www.scala-sbt.org/0.12.4/docs/Detailed-Topics/Macro-Projects.html),包括整个分发部分(所以本质上我有一个根项目,以及一个名为宏的子项目,其中包含正在使用的宏)
问题是,当我发布我的项目(现在使用 publish-local),而另一个 scala 项目使用带有宏的项目作为依赖项时,它会尝试提取 macro#macro_2.10;0.1-SNAPSHOT,因为它出现在聚甲醛。这会导致项目无法编译,因为它无法解决依赖关系,即
> compile
[info] Updating {file:/Users/mdedetrich/silvermanwylie/waitress/}default-0e4b9d...
[info] Resolving macro#macro_2.10;0.1-SNAPSHOT ...
[warn] module not found: macro#macro_2.10;0.1-SNAPSHOT
[warn] ==== local: tried
[warn] /Users/mdedetrich/.ivy2/local/macro/macro_2.10/0.1-SNAPSHOT/ivys/ivy.xml
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/macro/macro_2.10/0.1-SNAPSHOT/macro_2.10-0.1-SNAPSHOT.pom
[info] Resolving org.slf4j#slf4j-api;1.6.4 ...
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: macro#macro_2.10;0.1-SNAPSHOT: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[trace] Stack trace suppressed: run last *:update for the full output.
[error] (*:update) sbt.ResolveException: unresolved dependency: macro#macro_2.10;0.1-SNAPSHOT: not found
[error] Total time: 0 s, completed Aug 23, 2013 8:15:56 PM
如果我从 ivy-1.0.0-SNAPSHOT.xml 手动删除依赖项
<dependency org="macro" name="macro_2.10" rev="0.1-SNAPSHOT" conf="compile->default(compile)"/>
在常春藤缓存中,一切正常(项目编译并且它从依赖项中使用的宏工作正常)
这就是我的 Build.scala 的样子
import sbt._
import Keys._
object MacroBuild extends Build {
lazy val main = Project("main", file(".")) dependsOn(macroSub) settings(
// include the macro classes and resources in the main jar
mappings in (Compile, packageBin) <++= mappings in (macroSub, Compile, packageBin),
// include the macro sources in the main source jar
mappings in (Compile, packageSrc) <++= mappings in (macroSub, Compile, packageSrc)
)
lazy val macroSub = Project("macro", file("macro")) settings(
scalaVersion:= "2.10.2",
libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-compiler" % _),
publish := {},
publishLocal := {}
)
}
如何防止宏依赖出现在 POM 中?
编辑:为了清楚起见,问题不在于 scala-language 或 scala-reflect 被包含为依赖项,问题在于主(或根)项目取决于宏子项目,而它实际上不需要或使用它(因为它是一个宏)