我想要做的是将项目中预先创建的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/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')
}
}files
我还发现了一个名为“wuff”的项目,该项目旨在帮助使用Gradle构建OSGi项目。
发布于 2014-10-30 17:11:27
最后,我成功地使用以下代码获得了我想要的东西:
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/MANIFEST.MF文件,还包括由gradle动态管理的类路径依赖项。
https://stackoverflow.com/questions/26636534
复制相似问题