apply plugin: 'java'
version = '1.0'

// START SNIPPET add-to-manifest
jar {
    manifest {
        attributes("Implementation-Title": "Gradle", "Implementation-Version": version)
    }
}
// END SNIPPET add-to-manifest

// START SNIPPET custom-manifest
sharedManifest = manifest {
    attributes("Implementation-Title": "Gradle", "Implementation-Version": version)
}
task fooJar(type: Jar) {
    manifest = project.manifest {
        from sharedManifest
    }
}
// END SNIPPET custom-manifest

// START SNIPPET merge
task barJar(type: Jar) {
    manifest {
        attributes key1: 'value1'
        from sharedManifest, 'src/config/basemanifest.txt'
        from('src/config/javabasemanifest.txt', 'src/config/libbasemanifest.txt') {
            eachEntry { details ->
                if (details.baseValue != details.mergeValue) {
                    details.value = baseValue
                }
                if (details.key == 'foo') {
                    details.exclude()
                }
            }
        }
    }
}
// END SNIPPET merge

// START SNIPPET write
jar.manifest.writeTo("$buildDir/mymanifest.mf")
// END SNIPPET write
