我正在尝试为所有子项目(大约 30 个)定义一个 jar 任务。我尝试了以下任务:
jar {
destinationDir = file('../../../../_temp/core/modules')
archiveName = baseName + '.' + extension
metaInf {
from 'ejbModule/META-INF/' exclude 'MANIFEST.MF'
}
def manifestClasspath = configurations.runtime.collect { it.getName() }.join(',')
manifest {
attributes("Manifest-Version" : "1.0",
"Created-By" : vendor,
"Specification-Title" : appName,
"Specification-Version" : version,
"Specification-Vendor" : vendor,
"Implementation-Title" : appName,
"Implementation-Version" : version,
"Implementation-Vendor" : vendor,
"Main-Class" : "com.dcx.epep.Start",
"Class-Path" : manifestClasspath
)
}
}
我的问题是,子项目之间的依赖关系不包含在 list 的类路径中。我尝试将运行时配置更改为编译配置,但这导致以下错误。
- What went wrong: A problem occurred evaluating project ':EskoordClient'.
You can't change a configuration which is not in unresolved state!
这是我的 EskoordClient 项目的完整构建文件:dependencies { compile project(':ePEPClient') }
我的大多数子项目构建文件只定义了项目依赖项。在 super 项目的构建文件中定义了第 3 方 lib 依赖项。
是否有可能将所有需要的类路径条目(第 3 方库和其他项目)包含到所有子项目的 super 项目中的 list 类路径中。
最佳答案
这就是我让它工作的方式。仅使用以下调用获取项目依赖项:
getAllDependencies().withType(ProjectDependency)
然后将每个项目的 libsDir 的内容添加到我的类路径 list 条目中。
jar {
manifest {
attributes 'Main-Class': 'com.my.package.Main'
def manifestCp = configurations.runtime.files.collect {
File file = it
"lib/${file.name}"
}.join(' ')
configurations.runtime.getAllDependencies().withType(ProjectDependency).each {dep->
def depProj = dep.getDependencyProject()
def libFilePaths = project(depProj.path).libsDir.list().collect{ inFile-> "lib/${inFile}" }.join(' ')
logger.info"Adding libs from project ${depProj.name}: [- ${libFilePaths} -]"
manifestCp += ' '+libFilePaths
}
logger.lifecycle("")
logger.lifecycle("---Manifest-Class-Path: ${manifestCp}")
attributes 'Class-Path': manifestCp
}
}
关于jar - 在 gradle 中为 jar list 定义自定义类路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11469481/