我要做的是将我项目中预先创建的manifest.mf文件与gradle中jar任务的动态创建的清单文件结合起来。
有没有办法做到这一点?目前我完全生成我的清单文件: -
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
}
}
我知道我将有一个/META-INF/MANIFEST.MF文件。
最初我使用的是Gradle的OSGI插件,但这似乎忽略了清单文件并产生了巨大的混乱。
修改的
我已经对此进行了相当多的研究,感谢carlo我发现以下代码将允许我阅读现有的MANIFEST.MF: -
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
我还发现了一个名为“wuff'旨在帮助使用Gradle构建OSGi项目。
答案 0 :(得分:3)
最后,我使用以下代码设法得到了我想要的东西: -
jar.doFirst {
manifest {
def manifestFile = "${projectDir}/META-INF/MANIFEST.MF"
if ( new File( manifestFile ).exists() )
from ( manifestFile )
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
}
}
重要的是: -
def manifestFile = "${projectDir}/META-INF/MANIFEST.MF"
if ( new File( manifestFile ).exists() )
from ( manifestFile )
这允许我继承任何现有的/META-INF/MANIFEST.MF文件,并且还包括由gradle动态管理的类路径依赖项。