6
我正在做的是將我的項目中預先創建的manifest.mf文件與gradle中jar任務的動態創建的清單文件結合起來。Gradle Manifest.MF
有沒有辦法做到這一點?目前我正在生成我的清單文件完全: -
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插件,但是這似乎忽略了清單文件併產生了巨大的混亂。
編輯
我看着這個頗有幾分,感謝卡羅我發現下面的代碼可以讓我看現有的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項目。
https://github.com/akhikhl/wuff