Andrey
Andrey

Reputation: 75

Downgrade java target version in cyclically dependent libraries

Library A has a dependency on library B, B has a dependency on A. Now A and B use java 11. I need to downgrade it's java target version to 8 because of my project issues. How can i do that?

In libraries i use gradle 6.4.1. When i try to change sourceCompatibility and targetCompatibility to 1.8 build fails with expected message:

- Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8

UPD: libraries have modules, so one module of A library has dependency on some modules in B, and so on. There is no two modules from A and B, which dependent on each other

I think i found a dirty solution: downgrade java target version in modules which are independent of modules with target version = 11, release library, repeat. When all modules downgraded, it's ok to downgrade whole libraries. If someone knows better solution, please tell me

Upvotes: 2

Views: 6630

Answers (1)

Bishnu
Bishnu

Reputation: 11

  1. First of all, Cyclic dependency is a bad practice, you have to remove this by refactoring or by moving the classes to right module.
  2. As you are downgrading the java version from 11 to 8, you have to downgrade the dependent jars/libraries to java 8 compatible. There is a tricky situation that we have to produce a jar file with module-info that builds and runs on Java 8, 9, 10 and 11.

Upvotes: 1

Related Questions