Search code examples
scalagradlejargradle-kotlin-dsl

gradle include scala version in jar artifact name using kotlin DSL


How can I rename the produced jar by the gradle scala plugin using gradle build task to include the scala version name? I believe this property is called: archivesBaseName. It is made available from the java plugin (https://docs.gradle.org/current/dsl/org.gradle.api.Project.html#org.gradle.api.Project:archivesBaseName).

NOTE: I would want to accomplish this task using the kotlin DSL.

For the shadow jar:

id("com.github.johnrengelman.shadow") version "5.2.0" apply false
val shadowJar: com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar by tasks
    shadowJar.apply {
        archiveBaseName.set("${project.name}_2.12-all")
    }
    tasks {
        build {
            dependsOn(shadowJar)
        }

already works fine, but I would want to change the regular output as well.

I.e.:

archivesBaseName = "asdf"//"${project.name}_${sparkVersion}_${scalaVersionShort}"

usually works. But I have not figured out how to get this to work in the Kotlin DSL


Solution

  • base.archivesBaseName = "gradle"

    https://chromium.googlesource.com/external/github.com/gradle/gradle/+/cf6d0508131b0ff9d6354b3d46f83bcf5ca8f8a4/build.gradle.kts#45

    gets the job done