SBT包在增强已编译的类之后生成空的JAR



我是SBT插件的作者:https://github.com/atais/sbt-eclipselink-static-weave
其目的是使用提供的StaticWeaveProcessor增强编译的类。

为了实现这一步骤,我用替代了compile步骤

override def projectSettings: Seq[Def.Setting[_]] = Seq(
... 
// https://www.scala-sbt.org/1.0/docs/Howto-Dynamic-Task.html#build.sbt+v2
compile in Compile := Def.taskDyn {
val c = (compile in Compile).value
Def.task {
(copyResources in Compile).value // we need to copy META-INF folder first, https://github.com/sbt/sbt/issues/3934
weaveTask.value
c
}
}.value
)

问题

使用此插件的项目可以正确编译,但它们可能会生成一个空的jar,在packagepublish期间编译的源不可用。

您可能想查看我的pull请求,我已经准备了一个带有测试场景的测试项目。https://github.com/atais/sbt-eclipselink-static-weave/pull/2

详细信息

我已经尝试打印所有的设置和映射,但它们看起来很好。

然而,我发现Package.Configuration步骤使用cacheStoreFactory: CacheStoreFactory,我认为这是我的问题。

在函数makeJar(sources.toSeq, jar.file, manifest, log)中,有一个log.debug(sourcesDebugString(sources)),它在第一次运行时给出空结果:

[info] Finished EclipseLink static weaving in 610 ms.
[info] Packaging /home/atais/Documents/sbt-eclipselink-static-weave/sbt-test/target/scala-2.12/test_2.12-0.1.0-SNAPSHOT.jar ...
[debug] Input file mappings:
[debug]   

但正确地列出了第二个:上的文件

[info] Finished EclipseLink static weaving in 559 ms.
[info] Packaging /home/atais/Documents/sbt-eclipselink-static-weave/sbt-test/target/scala-2.12/test_2.12-0.1.0-SNAPSHOT.jar ...
[debug] Input file mappings:
[debug]         META-INF/persistence.xml
[debug]           /home/atais/Documents/sbt-eclipselink-static-weave/sbt-test/target/scala-2.12/classes-weaved/META-INF/persistence.xml
[debug]         META-INF
[debug]           /home/atais/Documents/sbt-eclipselink-static-weave/sbt-test/target/scala-2.12/classes-weaved/META-INF
[debug]         com
[debug]           /home/atais/Documents/sbt-eclipselink-static-weave/sbt-test/target/scala-2.12/classes-weaved/com
[debug]         META-INF/orm-rtb.xml
[debug]           /home/atais/Documents/sbt-eclipselink-static-weave/sbt-test/target/scala-2.12/classes-weaved/META-INF/orm-rtb.xml
[debug]         com/github/atais/entity
[debug]           /home/atais/Documents/sbt-eclipselink-static-weave/sbt-test/target/scala-2.12/classes-weaved/com/github/atais/entity
[debug]         com/github
[debug]           /home/atais/Documents/sbt-eclipselink-static-weave/sbt-test/target/scala-2.12/classes-weaved/com/github
[debug]         com/github/atais
[debug]           /home/atais/Documents/sbt-eclipselink-static-weave/sbt-test/target/scala-2.12/classes-weaved/com/github/atais
[debug]         com/github/atais/entity/EntityB.class
[debug]           /home/atais/Documents/sbt-eclipselink-static-weave/sbt-test/target/scala-2.12/classes-weaved/com/github/atais/entity/EntityB.class
[debug]         com/github/atais/entity/EntityA.class
[debug]           /home/atais/Documents/sbt-eclipselink-static-weave/sbt-test/target/scala-2.12/classes-weaved/com/github/atais/entity/EntityA.class

SBT在两次运行之间不会重新启动。这只是我第二次叫包裹了。

我如何才能在第一次运行时生产出合适的罐子?

好吧,原来我应该使用

productDirectories in Compile := Seq(weavedClassesDest.value),

而不是

products in Compile := Seq(weavedClassesDest.value),

现在它似乎在上工作

相关内容

最新更新