intellij-ideagradlegradlefx

How to get the full path to external dependencies in Gradle?


I am trying to improve GradleFX's IntelliJ IDEA project generation feature and want to retrieve the full path + filename for external dependencies:

// 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?
        }
    }
}

The original code for this function is at https://github.com/GradleFx/GradleFx/blob/develop/src/main/groovy/org/gradlefx/ide/tasks/idea/IdeaProject.groovy , I want to get the addDependencies() function working for external dependencies.
How can I get the full path + filename to external dependencies?


Solution

  • The code below should give You set of files that are resolved as dependencies:

    def files = project.configurations[configType].files(externalDependency)