need help: did you guys have this issue caching gr...
# gradle
m
need help: did you guys have this issue caching gradle plugins with docker? https://www.reddit.com/r/gradle/comments/ezvqc5/gradle_docker_springboot_kotlin/ any guess?
t
do you basically want to trigger downloading all your project dependencies?
m
the plugin dependencies. But only once
it is downloading everytime gradle runs
t
I would say in your docker image define user image will run under and then run
./gradlew buildEnvironment
task as a build step
m
hmm... I will try that
I tested here...
Copy code
RUN gradle dependencies buildEnvironment --build-cache --no-daemon
RUN gradle build --no-daemon --offline -x test
failed again:
Copy code
FAILURE: Build failed with an exception.

* Where:
Build file '/app/build.gradle.kts' line: 27

* What went wrong:
Plugin [id: 'org.springframework.boot', version: '2.2.4.RELEASE'] was not found in any of the following sources:
t
then you may add following task:
Copy code
open class DownloadDependenciesTask @Inject constructor(
    objectFactory: ObjectFactory
) : DefaultTask() {
    private val artifactTypeAttribute = Attribute.of("artifactType", String::class.java)

    @get:Internal
    val artifactTypes = objectFactory.setProperty(String::class).apply {
        set(setOf("jar", "aar", "apk"))
    }

    @get:Internal
    internal val buildScriptConfiguration = project.buildscript.configurations
        .matching { it.isCanBeResolved }

    @get:OutputFiles
    internal val artifactFiles: MutableList<File> = mutableListOf()

    @TaskAction
    fun syncDependencies() {
        buildScriptConfiguration
            .forEach { configuration ->
                configuration.incoming.resolutionResult.allDependencies
                resolveConfiguration(configuration, artifactTypes.get(), artifactTypeAttribute)
            }
    }

    private fun resolveConfiguration(
        configuration: Configuration,
        artifactTypes: Set<String>,
        artifactTypeAttribute: Attribute<String>
    ) {
        artifactTypes.forEach { type ->
            configuration
                .incoming
                .artifactView {
                    isLenient = true
                    attributes {
                        attribute(artifactTypeAttribute, type)
                    }
                }
                .artifacts
                .forEach {
                    <http://logger.info|logger.info>("Syncing artifact: $it")
                    artifactFiles.add(it.file)
                }
        }
    }
}
and trigger it via gradle. It should download all build script dependencies including plugins
m
tks @tapchicoma, I will try that