首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >gradle 6.x kotlin spring-boot jar发布失败,需要在gradle-kotlin-dsl中解决办法

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

Stack Overflow用户
提问于 2020-02-26 02:58:14
回答 1查看 581关注 0票数 3

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

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

代码语言:javascript
复制
configurations {
   [apiElements, runtimeElements].each {
       it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
       it.outgoing.artifact(bootJar)
   }
}

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

代码语言:javascript
复制
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中做这个出色的变通方法的想法?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-26 04:48:12

jarbootJar似乎是Gradle任务。您可以在Kotlin DSL中获得对任务的引用,如下所示:

代码语言:javascript
复制
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)
   }
}
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60401481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档