宏依赖性出现在POM/JAR中 [英] Macro dependancy appearing in POM/JAR

查看:129
本文介绍了宏依赖性出现在POM/JAR中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用宏的scala项目,该宏基本上遵循此处描述的确切方法(

I have a scala project that uses macros which basically follows the exact method described here (http://www.scala-sbt.org/0.12.4/docs/Detailed-Topics/Macro-Projects.html) including the whole Distribution section (so in essence I have a root project, and a subproject called macro which holds the macros being used)

问题是,当我发布项目(现在使用publish-local),而另一个scala项目使用带有宏的项目作为依赖项时,它尝试提取宏#macro_2.10; 0.1-SNAPSHOT,因为它出现在POM中.这会导致项目无法编译,因为它无法解决依赖关系,即

The problem is, when I publish my project (using publish-local for now), and another scala project uses the one with a macro as a dependency, it tries to pull macro#macro_2.10;0.1-SNAPSHOT since it appears in the POM. This causes project to fail to compile as it can't resolve the dependency, i.e.

> 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中删除依赖项

If I manually remove the dependency from ivy-1.0.0-SNAPSHOT.xml

<dependency org="macro" name="macro_2.10" rev="0.1-SNAPSHOT" conf="compile->default(compile)"/>

在常春藤缓存中,一切都可以正常工作(项目可以编译,并且依赖项使用的宏也可以正常工作)

In ivy cache then everything works fine (the project compiles and the macro it is using from the dependency works fine)

这是我的Build.scala的样子

This is what my Build.scala looks like

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中?

How do I prevent the macro dependency from appearing in the POM?

需要明确的是,问题不在于包含scala语言或scala-reflect作为依赖项,而是主要(或根)项目取决于宏子项目,而实际上根本不需要或使用它(因为它是一个宏)

Just to be clear, the issue is not with scala-language or scala-reflect being included as a dependency, the issue is with the main (or root) project depending on the macro sub project when it never actually needs or uses it (since its a macro)

推荐答案

链接文档中的Build.scala是一个多项目构建:

The Build.scala in the linked document is a multi-project build:

import sbt._
import Keys._

object MacroBuild extends Build {
   lazy val main = Project("main", file(".")) dependsOn(macroSub)
   lazy val macroSub = Project("macro", file("macro")) settings(
      libraryDependencies <+= scalaVersion("org.scala-lang" % "scala-compiler" % _)
   )
}

这意味着宏类文件将位于另一个jar中,如果其他项目要使用它,则必须同时publish(或publish-local)您的主项目和宏项目.

This means that the macro class files will be in another jar, and you have to publish (or publish-local) both your main project and the macro project if other project wants to use it.

> project macro
> publish-local

这篇关于宏依赖性出现在POM/JAR中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆