Can't add to jar file manifest

I tried adding the jar{} section to my build.gradle file to set some extra manifest entries. But none of the entries appear in the jar files produced (either the sourcesJar or the library). I suspect they are being clobbered by something in the plugins. How do I get this to work?

import java.text.SimpleDateFormat

plugins {
    id 'java'
    id 'maven-publish'
    id 'checkstyle'
    id 'org.springframework.boot' version '2.6.6'
    id 'com.github.spotbugs' version '5.0.4'
    id 'com.google.protobuf' version '0.8.18'
}

... repos, dependencies, protobuf config, then...

task sourcesJar(type: Jar) {
    from "src/main/java"
    from "src/main/proto"
    from "src/main/resources"
    from "${buildDir}/generated/source/proto/main/grpc"
    from "${buildDir}/generated/source/proto/main/java"
    archiveClassifier = 'sources'
    dependsOn("generateProto")
}

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
    options.warnings = false
    dependsOn("sourcesJar")
}

java {
    withSourcesJar()
}

jar {
    manifest {
        attributes(
                'Implementation-Title': "ProjectName",
                'Implementation-Version': archiveVersion,
                'Build-Time': new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ").format(new Date())
        )
    }
}
...

I suspect you’re getting tripped up by the spring boot plugin. Instead of configuring the jar task, configure the bootJar task (or configure both if that’s appropriate for your use case).

Here’s a bit of info about the bootJar task.

Thank you. That was it.

1 Like