Is it possible to exclude versions of a dependency...
# community-support
s
Is it possible to exclude versions of a dependency based on it's suffix? We have a library where we are trying to avoid anything that ends in preview . Right now I can exclude one at a time with the following. However, I was hoping that there is a way to do something that will work for all versions that end in
preview
.
Copy code
dependencies {
    jdbcDriver 'com.microsoft.sqlserver:mssql-jdbc:latest.integration'
...
    constraints {
            jdbcDriver('com.microsoft.sqlserver:mssql-jdbc') {
                version { 
                    reject '12.9.0.jre+' // or '12.9.0.jre11-preview'
                }
            }
...
}
s
I put in
Copy code
configurations {
...
	jdbcDriver.resolutionStrategy = {
		componentSelection { rules ->
			rules.all { ComponentSelection selection ->
				if (selection.candidate.version ==~ /.*preview*/) {
					selection.reject('preview version')
				}
			}
		}
	}
}
However, that generates this error. Not sure how to resolve this.
Copy code
* What went wrong:
A problem occurred evaluating root project 'test'.
> Cannot set the value of read-only property 'resolutionStrategy' for configuration ':jdbcDriver' of type org.gradle.api.internal.artifacts.configurations.DefaultUnlockedConfiguration.
e
resolutionStrategy {
not
resolutionStrategy = {
s
d'oh! Good catch.ðŸ«