Search code examples
javagradlegroovymanifest

Gradle - Customize Classpath in Manifest


I want to create a more general Classpath, than what is generated from this snippet of my build.gradle file:

jar {
manifest {
    attributes (
        "Main-Class": "x.y.z.main",
        "Specification-Title" : "Oh how specific!",
        "Specification-Vendor" : "Super Secret",
        "Specification-Version" : "1.0", 
        "Implementation-Title" : "Top Notch Software",
        "Implementation-Version" : "1.0 Build Nr. 1",
        "Implementation-Vendor" : "Super Secret",
        "Implementation-Vendor-Id" : "x.y.z.com",
        "Implementation-Url" : "http://www.x.y.z.com",
        "Class-Path": configurations.runtimeClasspath.files.collect { it.absolutePath }.join(' ')
    )
}

This yields something like this:

...Class-Path: C:\Users\YouWouldLikeToKnow\.gradle\caches\modules-2\files-2.1\org.springframework.cloud\spring-cloud-starter-gateway\3.1.3\d008ce51415d0507a1806bd0a518a21860ee0f63\spring-cloud-starter-gateway-3.1.3.jar...

Instead i want to configure it to be like so:

...Class-Path: libs\external\spring-cloud-starter-gateway-3.1.3.jar...

Something like:

configurations.runtimeClasspath.files.collect {"libs\external\" + it.fileName}.join(' ')

Solution

  • Could you try:

    'Class-Path': configurations.runtime.files.collect{ "lib/external/" + it.getName() }.join(' ')