Macro dependancy appearing in POM/JAR

萝らか妹 提交于 2019-12-10 10:56:17

问题


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)

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

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)

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 := {}
   )
}

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

EDIT: 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)


回答1:


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

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



回答2:


In your main project definition, you can replace dependsOn(macroSub) with dependsOn(macroSub % "compile-internal"). This won't add the macro project as a dependency to the POM.



来源:https://stackoverflow.com/questions/18400538/macro-dependancy-appearing-in-pom-jar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!