【问题标题】:gradle 6.x kotlin spring-boot jar publish fails, workaround in gradle-kotlin-dsl neededgradle 6.x kotlin spring-boot jar 发布失败,需要 gradle-kotlin-dsl 中的解决方法
【发布时间】:2020-06-09 14:12:41
【问题描述】:

gradle 6.x release notes 告诉我们 boot-jars 的 maven-publishing 不起作用,因为 spring-boot 插件禁用了默认的 jar 任务。

一种解决方法是告诉 Gradle 要上传什么。如果要上传 bootJar,则需要配置传出配置来执行此操作:

configurations {
   [apiElements, runtimeElements].each {
       it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
       it.outgoing.artifact(bootJar)
   }
}

不幸的是,我所有将其转换为 gradle-kotlin-dsl 的尝试都失败了:


configurations {
   listOf(apiElements, runtimeElements).forEach {
       it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
       it.outgoing.artifact(bootJar)
   }
}

* What went wrong:
Script compilation errors:

it.outgoing.artifacts.removeAll { it.buildDependencies.getDependencies(null).contains(jar) }
                                                                             ^ Out-projected type 'MutableSet<CapturedType(out (org.gradle.api.Task..org.gradle.api.Task?))>' prohibits the use of 'public abstract fun contains(element: E): Boolean defined in kotlin.collections.MutableSet'

it.outgoing.artifacts.removeAll { it.buildDependencies.getDependencies(null).contains(jar) }
                                                                                      ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
                                                                                                             public val TaskContainer.jar: TaskProvider<Jar> defined in org.gradle.kotlin.dsl
it.outgoing.artifact(bootJar)
                     ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: public val TaskContainer.bootJar: TaskProvider<BootJar> defined in org.gradle.kotlin.dsl

关于如何在 Gradle Kotlin DSL 中执行此常规解决方法的任何想法?

【问题讨论】:

    标签: gradle kotlin gradle-kotlin-dsl spring-boot-gradle-plugin maven-publish


    【解决方案1】:

    jarbootJar 似乎是 Gradle 任务。您可以像这样在 Kotlin DSL 中获得对任务的引用:

    configurations {
       listOf(apiElements, runtimeElements).forEach {
           // Method #1
           val jar by tasks
           it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
    
           // Method #2
           it.outgoing.artifact(tasks.bootJar)
       }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-07-29
      • 1970-01-01
      • 2020-11-20
      • 1970-01-01
      • 2021-11-08
      • 2018-11-05
      • 2019-03-06
      • 2018-10-19
      • 1970-01-01
      相关资源
      最近更新 更多