我正在编写一个执行监视/OpenTracing 的库,并且我正在尝试使用 sbt-aspectj,以便库的用户不需要手动检测他们的代码。但是,我目前在创建代表此类库的 sbt-project 时遇到问题。
这个想法是我想要一个外部库,如这里示例中所示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
使用发布项目root/publishLocal
,而测试项目只是设计为包含在内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