【问题标题】:Gradle Shadow Plugin dependencies not present in runtimeClasspath运行时类路径中不存在 Gradle Shadow 插件依赖项
【发布时间】:2019-10-20 21:31:43
【问题描述】:

我使用 Gradle Shadow 插件添加的 shadow 范围配置依赖项:

依赖{ 影子“org.apache.flink:flink-java:$flinkVersion” }

根据文档,此依赖项不应出现在影子 JAR 中(这是真的),它应该在编译类路径上(with 也是如此),但我对 runtimeClasspath 配置没有这种依赖关系。我做错了什么?

【问题讨论】:

    标签: gradle gradle-shadow-plugin


    【解决方案1】:

    我怀疑文档有误。 Shadow 从 runtimeClasspath 配置构建 jar,这使得无法从运行时依赖项构建不同的工件。 https://github.com/johnrengelman/shadow/blob/829647a06971ebc96c7d3df717f9a4e92811b602/src/main/groovy/com/github/jengelman/gradle/plugins/shadow/ShadowJavaPlugin.groovy#L84-L85

    可以通过中间配置和重定向 shadow 来为runtimeClasspath 贡献解决方法

    configurations {
        // alternative "runtimeClasspath" configuration to provide to shadowJar configuration
        create("uberJar") {
            extendsFrom(configurations.runtimeOnly.get(), configurations.implementation.get())
            isCanBeResolved = true
            isCanBeConsumed = false
        }
    }
    
    configurations.runtimeClasspath {
        extendsFrom(configurations.shadow.get())
    }
    
    tasks.shadowJar {
        configurations = listOf(project.configurations.named("uberJar").get())
    }
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-06
      • 2017-01-28
      • 2013-06-29
      • 2011-12-16
      • 1970-01-01
      • 2015-12-21
      • 2018-01-07
      相关资源
      最近更新 更多