How to override version only for test compile and running tests

In production, google cloud connector for jdbc is used and drags in a new version of guava. This version of guava does not work with latest selenium which is on an older guava. I am using guava in tests so I would like to at runtime use the older guava jar for selenium. I tried changing compileClasspath to testCompileClasspath(a complete guess) following this

https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

That didn’t seem to work though. 2 questions

  1. How do I list configurations so I don’t have to guess and list them?
  2. What is the correct syntax for what I want above and can I just swap out compileClasspath to the something and what is that something?

This post is a copy of https://stackoverflow.com/questions/60423854/in-gradle-how-to-lock-a-jar-to-a-version-only-for-test-compile-and-test-run

Hi @deanhiller,

If I understand correctly, you want to define a different Guava version in testing. Then you can set a constraint on testImplementation. Which will reflect in test compilation and runtime.

dependencies {
  constraints {
    testImplementation("com.google.guava:guava:16.0.1")
    // or if you need to force a version down, you can make it strict: 
    // testImplementation("com.google.guava:guava:16.0.1!!")
  }
}

This is documented in the Java Library plugin docs:
https://docs.gradle.org/current/userguide/java_library_plugin.html#sec:java_library_configurations_graph

There is no built-in task or something to show you all configurations.

1 Like