【问题标题】:Exclude packages already contained in compileOnly dependency with gradle使用 gradle 排除已包含在 compileOnly 依赖项中的包
【发布时间】:2020-10-25 15:57:33
【问题描述】:

我正在寻找一些自动/简单的方法来从最终 jar 中排除所有依赖项,如果它们已经包含在最终 jar 中不存在但在外部加载的任何仅编译依赖项中。我正在使用 kotlin DSL 进行 gradle 配置。

我当前的 jar 配置:

withType<Jar> {
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    archiveClassifier.set("core")

    from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
    exclude(
            "kotlin/**"
    )
}

例如,我实现了 jackson yaml 格式,它使用蛇 YAML 作为依赖项。然而,snake YAML 也存在于一个 compileOnly 依赖项中,不应包含在最终 JAR 中。

如果我理解正确,runtimeClasspath 只包含实现依赖,还包含它们的所有依赖,这就是问题所在

【问题讨论】:

    标签: java kotlin gradle jar gradle-kotlin-dsl


    【解决方案1】:

    你可以有一个自定义任务来创建你想要打包的jar列表,​​下面sn-p显示runtime-compileonly

    task runCP() {
        def runList = configurations.runtimeClasspath.asList()
        def compileOnlyList = configurations.compileOnly.asList()
        println(runList.join("\n"))
        println("----")
        println(compileOnlyList.join("\n"))
        println("====")
        println(runList.size() + " | " + runList.removeAll(compileOnlyList) + " | " + runList.size())
        println(runList.join("\n"))
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-14
      • 1970-01-01
      • 2021-12-25
      • 1970-01-01
      • 2016-02-19
      • 1970-01-01
      相关资源
      最近更新 更多