What I want to do is combine as a pre-created manifest.mf file from my project with a dynamically created manifest file from the jar task in gradle.
Is there any way to do this? I am currently fully creating manifest files: -
jar.doFirst { manifest { def requiredProjects = '' configurations.compile.getAllDependencies().withType(ProjectDependency).each {dep-> def dependantProjects = dep.getDependencyProject() def projects = project(dependantProjects.path).libsDir.list().findAll{it.endsWith('.jar')} projects.removeAll(projects.findAll{it.endsWith('test.jar')}) def requiredProject = projects.join(' ') requiredProjects += requiredProject.replaceAll(/ /,'%20') + ' ' logger.info 'Required Project: ' + requiredProject } logger.info 'Required requiredProjects: ' + requiredProjects def compileFiles = configurations.compile.files{ it instanceof ExternalDependency }.collect { File file = it "lib/${file.name}" }.join(' ') def manifestPath = requiredProjects + compileFiles logger.info 'Manifest: '+ manifestPath attributes 'Class-Path': manifestPath attributes 'Build-date': new Date(); attributes 'Application-Version': project.version } }
I know that I will have the file / META -INF / MANIFEST.MF.
I originally used the OSGI plugin for Gradle, but this seems to ignore the manifest file and creates a huge mess.
Edit
I learned this quite a lot, thanks to carlo, I found the following code that will allow me to read the existing MANIFEST.MF file: -
jar { onlyIf { !compileJava.source.empty } manifest { // benutze das im Projekt vorliegende File, falls vorhanden: def manif = "${projectDir}/META-INF/MANIFEST.MF" if (new File(manif).exists()) { from (manif) { eachEntry { details -> if (details.key == 'Bundle-Vendor') { details.value = 'xyz GmbH' } } } } else { logger.info(project.name + " doesn't have a META-INF/MANIFEST.MF.") manifest.attributes provider: xyz GmbH' manifest.attributes project: project.name manifest.attributes Build: new Date() } } // copy if we have these: from file ('plugin.xml') from file ('plugin.properties') into ('icons') { // if any ... from fileTree('icons') } }
http://forums.gradle.org/gradle/topics/how_to_deal_with_eclipse_projects_and_manifest_files
I also found a project called "wuff" whose purpose is to create OSGi projects using gradle.
https://github.com/akhikhl/wuff
source share