我正在尝试改进GradleFX的IntelliJ IDEA项目生成功能,并希望检索外部依赖项的完整路径+文件名:
// Generate the dependencies XML for the .iml file:
[
Configurations.INTERNAL_CONFIGURATION_NAME.configName(),
Configurations.EXTERNAL_CONFIGURATION_NAME.configName(),
Configurations.MERGE_CONFIGURATION_NAME.configName(),
Configurations.RSL_CONFIGURATION_NAME.configName(),
Configurations.TEST_CONFIGURATION_NAME.configName(),
Configurations.THEME_CONFIGURATION_NAME.configName()
].each { configType ->
project.configurations[configType].allDependencies.each { Dependency dependency ->
if (dependency instanceof DefaultProjectDependency) {
// generate XML for a module dependency, no need for the file
} else if (dependency instanceof DefaultSelfResolvingDependency) {
def selfDependency = dependency as DefaultSelfResolvingDependency;
selfDependency.source.files.each { file ->
// generate XML for a dependency
}
} else if (dependency instanceof DefaultExternalModuleDependency) {
DefaultExternalModuleDependency externalDependency = dependency as DefaultExternalModuleDependency;
// This is an external dependency.
// How to get a reference to the actual file in the cache?
}
}
}
此函数的原始代码位于https://github.com/GradleFx/GradleFx/blob/develop/src/main/groovy/org/gradlefx/ide/tasks/idea/IdeaProject.groovy,我想让addDependencies()函数适用于外部依赖项。
如何获得外部依赖项的完整路径+文件名?
答案 0 :(得分:3)
下面的代码应该为您提供一组解析为依赖项的文件:
def files = project.configurations[configType].files(externalDependency)