问题描述
6.x版发行说明告诉我们 ing不起作用,因为默认的jar
任务已被spring-boot插件禁用.
gradle 6.x release notes tells us that maven-publish
ing of boot-jars doesn't work because the default jar
task is disabled by the spring-boot plugin.
一种解决方法是告诉Gradle上传什么.如果要上载bootJar,则需要配置传出配置以执行此操作:
A workaround is to tell Gradle what to upload. If you want to upload the bootJar, then you need to configure the outgoing configurations to do this:
configurations {
[apiElements, runtimeElements].each {
it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
it.outgoing.artifact(bootJar)
}
}
不幸的是,我尝试将其转换为gradle-kotlin-dsl的所有尝试均失败:
unfortunately all my tries to translate this to gradle-kotlin-dsl fail:
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中执行这种常规解决方法的想法吗?
any idea on how to do this groovy workaround in Gradle Kotlin DSL?
推荐答案
jar
和bootJar
似乎是Gradle任务.您可以像这样在Kotlin DSL中获得对任务的引用:
jar
and bootJar
seems to be Gradle tasks. You can get a reference to a task in Kotlin DSL like this:
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中解决的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!