代码之家  ›  专栏  ›  技术社区  ›  Atais

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

  •  1
  • Atais  · 技术社区  · 7 年前

    我是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
      )
    

    问题

    使用此插件的项目可以正确编译,但是 可以 制作 空罐子 在期间 package 或 publish 如果 事先没有汇编的资料来源。

    您可能想检查我的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未重新启动 在这两次跑步之间。这是我第二次给包裹打电话。

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

    0 回复  |  直到 7 年前
        1
  •  0
  •   Atais    5 年前

    好吧,原来我应该用

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

    而不是

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

    现在它似乎起作用了