1

我正在尝试改进 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 () 函数为外部依赖工作。
如何获取外部依赖项的完整路径 + 文件名?

4

1 回答 1

3

下面的代码应该为您提供一组被解析为依赖项的文件:

def files = project.configurations[configType].files(externalDependency)
于 2014-10-31T12:01:41.517 回答