Java – how to create gradle sharedmanifest for multiple projects?

I have several Java projects These projects use gradle to create jar, war, and ear files In each project, I use manifest files to maintain metadata, such as version, date, time

manifest {
     attributes( 
    'Bundle-Vendor' : "$BUNDLE_VENDOR",'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")) 
}

But there is a function in gradle that calls sharedmanifest I'm in the main project build Two tasks are defined in the gradle script However, in each jar and war file, there is a default manifest created by gradle MF file

ext.sharedManifest = manifest {

    attributes( 
        'Bundle-Vendor' : "$BUNDLE_VENDOR",'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
     ) 
}

task fooJar(type: Jar) {
    manifest = project.manifest {
        from sharedManifest
    }
}

task fooWar(type: War) {
    manifest = project.manifest {
        from sharedManifest
    }
}

jar. manifest. writeTo( “/ MANIFEST.MF”) war. manifest. writeTo( “/ MANIFEST.MF”)

Please put forward suggestions on how to do this

Solution

The easiest way to share manifest logic in a build is to configure rules, such as:

allprojects {
    tasks.withType(Jar) { // includes War and Ear
        manifest {
            attributes ...
        }
    }
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>