1

When I execute in my Maven project the Versions Maven Plugin plugin with the command:

mvn versions:use-latest-versions

The pom.xml is updated with updated dependencies as it is supposed to do.

The problem is that some libraries are updated to version as new as the do not contains some of the packages used in previous versions so the compiler says package not found. Does anybody know how to avoid automatically? I mean, update to the latest version which have the packages and classes I am using in my code.

Lorenzo Lerate
  • 3,552
  • 3
  • 26
  • 25
  • I am not sure if I understand your usecase. Say you have package X listed as dependency. X depends on Y and you use Y too but do not list it explicitly as a dependency. Now you have versions plugin update and Y is no longer a dependency of X but you still use it in your code? – Matthias Nov 22 '16 at 10:33
  • I am making an assumption but I don't think the purpose of the plugin is to check if your code is still compiling after you upgrade your dependencies. In fact, this is quite dangerous as you might have (like you just said) source code that refers to deprecated method, etc... leading to errors. And there could be more than that : did you think about **licenses** ? Anyway, have a look here, there is good answers to your context : [here](http://stackoverflow.com/questions/30571/how-do-i-tell-maven-to-use-the-latest-version-of-a-dependency) – MadJlzz Nov 22 '16 at 10:37

3 Answers3

2

In my opinion, there is no easy way to determine which version update is "save".

Even if you would check that all classes you compile against still exist, method signatures might have changed. And even if all the method signatures stay the same, the behaviour might have changed, leading to runtime exception etc.

The only reasonable way I know to check a version update is to run a compile and run all test cases. Doing this for all combinations of possible version updates is possible but it will take a lot of time.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
2

The plugin is not going to analyse your code and adjust the dependencies version accordingly.

The objective of the goal use-latest-versions is to upgrade your project to the latest release of your project dependencies, and as a result of you may have compilation and deployment problems. Once you identified the problems you need to fix all the problems so that your whole project is upgraded to the latest releases of your dependencies.

Sajan Chandran
  • 11,287
  • 3
  • 29
  • 38
2

The problem is that some libraries are updated to version as new as the do not contains some of the packages used in previous versions so the compiler says package not found. Does anybody know how to avoid automatically? I mean, update to the latest version which have the packages and classes I am using in my code.

Of course, it is not possible.

Updating dependencies is not a game of chance.
If you need to have the last version of a dependency, you should not worry about if this version breaks or doesn't break your code because you need it.
You update a library because you need to update that version. If you don't need to update your dependencies, don't update your dependencies, but if you need to do that, you should make the work to update your code too if necessary.

davidxxx
  • 125,838
  • 23
  • 214
  • 215