Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gradle 6.x kotlin spring-boot jar publish fails, workaround in gradle-kotlin-dsl needed

gradle 6.x release notes tells us that maven-publishing of boot-jars doesn't work because the default jar task is disabled by the spring-boot plugin.

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

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

any idea on how to do this groovy workaround in Gradle Kotlin DSL?

like image 994
Dirk Hoffmann Avatar asked Feb 25 '20 18:02

Dirk Hoffmann


1 Answers

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)
   }
}
like image 145
madhead - StandWithUkraine Avatar answered Oct 03 '22 05:10

madhead - StandWithUkraine