Resolution strategy for classpath configuration?

Hi,

is it somehow possible to setup resolution strategy (forcing a dynamic version to a specific version) for the buildscript classpath’s configuration?

It does not not look like it is.

Thanks.

Yes, it is possible to use a resolution strategy for the buildscript classpath configuration. However, there are strict requirements since the buildscript { } block is executed and classpath is resolved before other code in the build.gradle is executed.

This will force the buildscan plugin to use version 1.9:

build.gradle

apply plugin: 'com.gradle.build-scan'
  
buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2' }
    }
    dependencies {
        classpath 'com.gradle:build-scan-plugin:latest.release'
    }
    configurations.classpath {
        resolutionStrategy {
            force 'com.gradle:build-scan-plugin:1.9'
        }
    }
}

Output

$ gradle buildEnvironment

> Task :buildEnvironment

------------------------------------------------------------
Root project
------------------------------------------------------------

classpath
\--- com.gradle:build-scan-plugin:latest.release -> 1.9


BUILD SUCCESSFUL in 0s
1 actionable task: 1 executed

It may not be very useful to have the resolution rule right with the dynamic version. If you need to extract the logic to somewhere else, you can do that, but you need to explicitly apply the other script to buildscript from buildscript { }:

pluginResolutionStrategy.gradle

configurations.classpath {
    resolutionStrategy {
        force 'com.gradle:build-scan-plugin:1.9'
    }
}

build.gradle

apply plugin: 'com.gradle.build-scan'
  
buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2' }
    }
    dependencies {
        classpath 'com.gradle:build-scan-plugin:latest.release'
    }
    apply from: 'pluginResolutionStrategy.gradle', to: buildscript
}