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 中执行此常规解决方法的任何想法?
最佳答案
jar
和 bootJar
似乎是 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/