Is there a proper or easy way of building one project for different JDK versions, the project would use different versions of its dependency depending on what JDK version it's built with.
I have a Java project that is built using JDK8, the project uses javax and its dependencies of course also uses JDK8. Now another project that uses this as a dependency is being upgraded to JDK 17, so that means I need to upgrade the dependency project to JDK 17 as well (I was getting compile errors due to javax), so I upgraded to jakarta and updated the dependencies to more recent versions (some now requiring JDK9 at minimum). This is all fine and I got everything working with JDK 17 and removed all traces of javax.
My dilemma though is this project is still actively updated and used as a dependency by other projects running on JDK8 (no chance of them being upgraded anytime soon) but since I upgraded it to JDK 17 they now get compile errors because of the jdk version difference. My only option now is to just publish 2 different versions, one jdk8 and one JDK 17.
The JDK8 would have dependencies with lower version because it's the final version compatible for JDK8, for example
dependecies {
implementation: 'org.example:dependency-a:1.5.0'
}
But the JDK 17 version would be upgraded (assume I can't use the lower version due to compatibility issues)
dependecies {
implementation: 'org.example:dependency-a:2.0.0'
}
Assuming all code stays the same for both version and it's just the dependencies that are different, is there a way for me to just have this on a single project and every time I build I would get a JDK8 and JDK 17 version of my project? My only other option is to just maintain 2 separate branches and update, build, and publish both when there are changes.
importstatements in at least some of your source files, and they appear in the corresponding class files as well. It may be that you can isolate the classes that must differ so as to maintain different branches only for these, but it's unclear whether that would provide enough advantage to be worth it.