Gradle 6.x Kotlin Spring Boot Jar发布失败,在Gradle-Kotlin-DSL中需要解决方法。

5

Gradle 6.x发布说明告诉我们,由于spring-boot插件禁用了默认的jar任务,因此maven-publish无法使用boot-jars。

解决方法是告诉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中实现这个Groovy解决方案的想法?

1个回答

6

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接