gradle 6.x kotlin spring-boot jar 发布失败,需要 gradle-kotlin-dsl 中的解决方法

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

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

一种解决方法是告诉 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 中执行此常规解决方法的任何想法?

最佳答案

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)
   }
}

关于gradle 6.x kotlin spring-boot jar 发布失败,需要 gradle-kotlin-dsl 中的解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60401481/

相关文章:

gradle - spring boot gradle文件中的 "tag::..."语法是什么?

android - 将 Realm-gradle-plugin :1. 0.0 添加到 Android Studio 项目时,Gradle 无法同步

maven - 声明性Jenkinsfile使用单独的阶段进行Maven/Gradle构建并发布到Artifactory

java - 如何从其他服务获取@GetMapping内部的路径

java - Spring Integration ErrorMessage 中的 null originalMessage

android - Material 设计build.gradle错误

kotlin - 是否可以使用插值字符串模板调用 kotlin 的 js 函数?

android - 如何使用 kotlin-dsl 在 gradle 中使用多种口味?

android - 如何从Android Project的build.gradle运行Kotlin任务?

android - buildFeatures 是不稳定的,因为它的签名引用了不稳定的 ... 标有 @Incubating