【发布时间】:2019-12-29 15:34:02
【问题描述】:
我正在编写一个用于监控/OpenTracing 的库,并且我正在尝试使用 sbt-aspectj,以便该库的用户无需手动检测他们的代码。但是,我目前在创建代表此类库的 sbt 项目时遇到了问题。
我的想法是我想要一个外部库,如此示例中所示https://github.com/sbt/sbt-aspectj/tree/master/src/sbt-test/weave/external 但是该外部库依赖于外部依赖项(即akka-actors)。基本上我正在尝试将https://github.com/sbt/sbt-aspectj/tree/master/src/sbt-test/weave/external 和https://github.com/sbt/sbt-aspectj/tree/master/src/sbt-test/weave/jar 结合起来。我在这里创建了一个示例项目https://github.com/mdedetrich/sbt-aspectj-issue 来说明我遇到的问题,但是下面是相关示例
lazy val root = (project in file("."))
.enablePlugins(SbtAspectj)
.settings(
name := RootName,
version := Version,
// add akka-actor as an aspectj input (find it in the update report)
// aspectjInputs in Aspectj ++= update.value.matching(
// moduleFilter(organization = "com.typesafe.akka", name = "akka-actor*")),
// replace the original akka-actor jar with the instrumented classes in runtime
// fullClasspath in Runtime := aspectjUseInstrumentedClasses(Runtime).value,
// only compile the aspects (no weaving)
aspectjCompileOnly in Aspectj := true,
// ignore warnings (we don't have the target classes at this point)
aspectjLintProperties in Aspectj += "invalidAbsoluteTypeName = ignore",
// replace regular products with compiled aspects
products in Compile ++= (products in Aspectj).value,
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % akkaVersion
)
)
lazy val test = (project in file("test"))
.enablePlugins(SbtAspectj)
.settings(
aspectjBinaries in Aspectj ++= update.value.matching(
moduleFilter(organization = Organization, name = s"$RootName*")),
aspectjInputs in Aspectj ++= update.value.matching(
moduleFilter(organization = "com.typesafe.akka", name = "akka-actor*")),
fullClasspath in Runtime := aspectjUseInstrumentedClasses(Runtime).value,
// weave this project's classes
aspectjInputs in Aspectj += (aspectjCompiledClasses in Aspectj).value,
products in Compile := (products in Aspectj).value,
products in Runtime := (products in Compile).value,
libraryDependencies ++= Seq(
Organization %% RootName % Version
)
)
我们的想法是我们使用root/publishLocal 发布root 项目,而测试项目只是设计为包含root 作为libraryDependency,因此我们可以查看aspect-j 是否正常工作。
问题很简单,我无法让它工作。 https://github.com/mdedetrich/sbt-aspectj-issue 的当前代码与 root/publishLocal 一起发布(虽然不确定它是否正确)但是当我这样做时 test/run 我明白了
[info] Weaving 2 inputs with 1 AspectJ binary to /home/mdedetrich/github/sbt-aspectj-issue/test/target/scala-2.13/aspectj/classes...
[error] stack trace is suppressed; run last test / Compile / packageBin for the full output
[error] (test / Compile / packageBin) java.util.zip.ZipException: duplicate entry: META-INF/MANIFEST.MF
[error] Total time: 1 s, completed Dec 29, 2019 4:31:27 PM
sbt:sbt-aspectj-issue>
这似乎是重复 akka-actor 条目的问题。我尝试切换 build.sbt 中的各种条目,但没有成功。
编辑:这也作为 github 问题发布在这里 https://github.com/sbt/sbt-aspectj/issues/44
【问题讨论】:
标签: scala sbt aspectj aspect sbt-aspectj