【问题标题】:Implementation Dependency Excluded from Runtime Configuration从运行时配置中排除的实现依赖性
【发布时间】:2019-09-16 19:00:36
【问题描述】:

在我的 gradle 文件中添加依赖项作为实现时,当它们作为运行时配置的一部分列出时,它们不会被包含在内。例如,当尝试将它们放入路径 jar 时,它们会被排除在外:

task pathingJar(type: Jar) {
    dependsOn configurations.runtime
    appendix = 'pathing'

    doFirst {
        manifest {
            attributes "Class-Path": configurations.runtime.files.collect {
                it.toURL().toString().replaceFirst(/file:\/+/, '/')
            }.join(' ')
        }
    }
}

但是,当将这些作为编译依赖项移回时,这是可行的。这个问题现在在编译时我的类路径要大得多。我的理解是实现应该被视为直接消费者和运行时传递的编译时间,那么为什么将它们排除在该配置之外?当将它们指定为“api”时,这也不起作用。这是使用 gradle 5.6.1。

【问题讨论】:

    标签: gradle


    【解决方案1】:

    runtime 配置已弃用,取而代之的是runtimeOnly。这个旧配置不知道新的implementationapi 配置,所以这就是为什么在解决它时看不到你的依赖关系。

    您想要的不是解析runtimeOnly 配置,而是解析运行时使用的类路径。此配置称为runtimeClasspath。示例:

    tasks.register("patchingJar", Jar) {
        dependsOn configurations.runtimeClasspath
        appendix = 'patching'
    
        doFirst {
            manifest {
                attributes "Class-Path": configurations.runtimeClasspath.files.collect {
                    it.toURL().toString().replaceFirst(/file:\/+/, '/')
                }.join(' ')
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-25
      • 1970-01-01
      • 2012-04-12
      • 2020-04-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多