Jar Manifest Classpath

I am migrating from goovy to Kotlin script and from 4.10.2 to 6.0.1 (and IntelliJ 2018.3 to 2019.2).

For my project I put all dependent jar files in the folder with my project jar and add their names to the Class-Path attribute in the manifest. My working 4.10.2 groovy code was:


task copyToLibs( type: Copy ) {
    into "$buildDir/libs"
    from configurations.compile
}

jar {
    dependsOn copyToLibs
    manifest {
        attributes(
                "Class-Path": configurations.compile.collect { it.name }.join(' ')
        )
    }
}

Converting to Kotlin I have:


tasks.register<Copy>("copyToLibs") {
    from(configurations.compileClasspath)
    into("$buildDir/libs")
}

tasks.named<Jar>("jar") {
    dependsOn("copyToLibs")
    manifest {
        attributes["Main-Class"] = "org.egility.flint.FlintMainKt"
        attributes["Class-Path"] = configurations.compileClasspath.joinToString(separator = " ") { it.name }
    }
}

This works fine for 4.10.2 but crashes out in 6.0.1 because of the “configurations.compileClasspath.joinToString” statement.

If I omit the statement everything else works and my files get copied correctly, but I need the manifest populated as well.

Can anyone suggest how I should be doing this. It has taken me a week so far to get my development tools up to date and this is the final problem and I would really like to get back to work.

Hello,
since gradle 5.0 if i remember correctly, confgiruations.compileClasspath returns Provider<Configuration> instead of Configuration (at least for kotlin DSL).
So you need to invoke confgiruations.compileClasspath.get().joinToString(separator = " ") { it.name }
Also i think you should use runtimeClasspath instead of compileClasspath because you need all dependencies needed to run against jar not just compile i presume.

Thanks, that works but am crashing elsewhere now. Will raise a new topic if necessary. For anyone who needs to know, the working code is now

tasks.register<Copy>("copyToLibs") {
    from(configurations.runtimeClasspath)
    into("$buildDir/libs")
}

tasks.jar {
    dependsOn("copyToLibs")
    manifest {
       attributes["Class-Path"] = configurations.runtimeClasspath.get().joinToString(" ") { it.name }
    }
}
1 Like