I donβt know how to do this - either at runtime or even at build time. There is no standard mechanism for determining package versions without examining manifests or jar file names, which would be a hack at best. Maybe there is a maven plugin that I don't know about, it does this automatically, but I don't know about that.
We simply fix the versions of the libraries that we need for our code, and update when we need it either because we need additional functions or another dependency. Usually we are ahead of other dependencies, so we put a typical exception marker in our dependency definitions in pom.xml
:
<dependency> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> <version>${spring-version}</version> <exclusions> <exclusion> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion>
This allows us to depend on a later version of commons-logging
.
If, however, you use 1.0 libraries, but one of your dependencies uses 2.0, then you will have to try exclusion
and see if the dependency works with 1.0 or even compilers. If not, you will either have to update the code to work with 2.0, or reduce the dependency.
Sorry I canβt help.
source share