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

Dir*_*ann 5 gradle kotlin maven-publish spring-boot-gradle-plugin gradle-kotlin-dsl

gradle 6.x 发行说明告诉我们maven-publishboot-jars 的 ing 不起作用,因为默认jar任务被 spring-boot 插件禁用。

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

configurations {
   [apiElements, runtimeElements].each {
       it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) }
       it.outgoing.artifact(bootJar)
   }
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,我所有将其转换为 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
Run Code Online (Sandbox Code Playgroud)

关于如何在 Gradle Kotlin DSL 中执行此绝妙解决方法有任何想法吗?

mad*_*ead 6

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)
   }
}
Run Code Online (Sandbox Code Playgroud)