How to cache dependency of a detached gradle configuration on CI?

Viewed 253

I'm trying to generate a full cache of dependencies for all project/scripts configurations before assemble step. I'd like to use --offline gradle flag for all jobs except the caching one.

So android plugin provides androidDependencies task which resolves all resolvable dependencies of a project

Previously we used a custom task which does the same:

task resolveDependencies {
    description "Resolves all projects dependencies from the repository."
    group "Build Server"

    doLast {
        rootProject.allprojects { project ->
            project.buildscript.configurations.forEach { configuration ->
                if (configuration.canBeResolved) {
                    try {
                        configuration.resolve()
                    } catch (ignored) {
                    }
                }
            }

            project.configurations.forEach { configuration ->
                if (configuration.canBeResolved) {
                    try {
                        configuration.resolve()
                    } catch (ignored) {
                    }
                }
            }
        }
    }
}

Unluckily some gradle scripts which are activated during assemble step use detachedConfigurations. These configurations are not visible and solved neither with androidDependencies task nor with the custom one

For example, android gradle build plugin throws the error during assemble step:

Execution failed for task ':app:mergeDebugResources'.
> A failure occurred while executing com.android.build.gradle.internal.res.Aapt2CompileRunnable
        > Could not isolate value com.android.build.gradle.internal.res.Aapt2CompileRunnable$Params_Decorated@3d617643 of type Aapt2CompileRunnable.Params
        > Could not resolve all files for configuration ':app:detachedConfiguration1'.
> Could not resolve com.android.tools.build:aapt2:7.1.3-7984345.
        Required by:
        project :app
        > No cached version of com.android.tools.build:aapt2:7.1.3-7984345 available for offline mode.

Is it possible to solve all detached configurations before the assemble task?

For now the only solution i see is to cache dependencies as well after the assemble task and forget about using --offline

Please also check related topic on circleCi forum

0 Answers
Related