gpt4 book ai didi

Gradle list .MF

转载 作者:行者123 更新时间:2023-12-02 06:36:33 26 4
gpt4 key购买 nike

我想要做的是将我的项目中预先创建的manifest.mf 文件与gradle 中的jar 任务动态创建的manifest 文件结合起来。

有什么办法可以做到这一点吗?目前我正在完全生成我的 list 文件:-

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 插件,但这似乎忽略了 list 文件并产生了巨大的困惑。

编辑

我对此进行了相当多的研究,感谢 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 项目。

https://github.com/akhikhl/wuff

最佳答案

最后我成功地使用以下代码得到了我想要的东西:-

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 动态管理的类路径依赖项。

关于Gradle list .MF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26636534/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com