5

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?

madhead
  • 31,729
  • 16
  • 153
  • 201
Dirk Hoffmann
  • 1,444
  • 17
  • 35

1 Answers1

6

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)
   }
}
madhead
  • 31,729
  • 16
  • 153
  • 201