简体   繁体   English

在 gradle 中更改传递依赖项的版本

[英]Changing version for a transitive dependency in gradle

I have a very weird requirement of using two different version for scala library.我有一个非常奇怪的要求,即为 scala 库使用两个不同的版本。

The scenario is that there are some very old tests are using scala library with a very older version and now when have created new Kafka Consumers and producers in the same package and scala transitively gets the latest version of scala.场景是有一些非常旧的测试正在使用具有非常旧版本的 scala 库,现在当在同一个包中创建新的 Kafka 消费者和生产者时,scala 会传递获取最新版本的 scala。

Is there a way I can run old tests on older version and new tests on newer version for scala.有没有办法可以在旧版本上运行旧测试并在新版本上运行新测试 scala。

I can share what we did for downgrading the Scala dependency when we used an older version of Spring Kafka in a Spring Boot context:当我们在 Spring Boot 上下文中使用旧版本的 Spring Kafka 时,我可以分享我们为降级 Scala 依赖项所做的工作:

dependencies {
  constraints {
    testImplementation('org.scala-lang:scala-library') {
      // See https://github.com/spring-projects/spring-kafka/issues/1623
      // This can be removed if upgrading Spring Kafka to 2.6
      because('There is a transitive dependency from Jackson to Scala that is not compatible with the version required by Apache Kafka')
      version {
        strictly '2.12.11'
      }
    }
  }
}

This will force the scala-library dependency to be a specific version for all tests.这将强制 scala-library 依赖项成为所有测试的特定版本。

If you want to run some tests in one version and some in another, and they are all in the same module, you are probably better of segregating your tests in different source sets.如果您想在一个版本中运行一些测试,而在另一个版本中运行一些测试,并且它们都在同一个模块中,那么您最好将测试隔离在不同的源集中。 You can read about this in the user guide here (though about integration testing, the same principle applies to other kinds of tests.)您可以在此处的用户指南中阅读相关内容(尽管关于集成测试,同样的原则也适用于其他类型的测试。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM