Monday, December 5, 2016

Maven compilation errors

    Have you ever experienced a situation when newly imported Maven project had some compilation errors? If so then this post is for you.
When you encounter a compilation error in a newly downloaded Maven project you need to check what's the origin of a given problem. I would classify Maven project compilation errors into two main categories:

1. Dependency used from within the project code introduces compilation error. It can occur in the following cases:

a). the dependency was deleted from remote Maven repository:
  • particular version was removed because it had some critical bugs (e.g. security related) and you should increase the dependency version number and then of course execute regression testing to check if nothing was broken by that,
  •  the dependency was totally removed, moved to a different location or renamed for some reason.
In both cases the project may still compile smoothly in the continuous integration system because the artifact could be stored in a continuous integration local Maven repository during previous builds.

b). you are unable to reach Maven repository containing the dependency:
  • Maven repository in which the dependency exists was not defined in pom.xml file or it is defined within a non-active Maven profile. It may be described in README.txt or Wiki of the project to add particular repositories to your settings.xml file. Personally, I do not like any README.txt files. I think that the project itself should be self-sufficient meaning in that case that the repositories should be defined in a root pom.xml,
  • you do not have an access to a given Maven repository - maybe some proxy or firewall rule must be added or you need to create a tunnel or connect to a certain VPN.
c). the release dependency was updated (difference from the binary perspective) without version changing and you have that version stored (old binary version) in your local Maven repository (C:\Users\YourUsername\.m2 [in Windows]). Compilation error may occur when there is a call to a non-existing method signature from the dependency (e.g. method was added to the newer binary version and Maven artifact version stayed the same). In that case we need to force Maven to update a release dependency. A release dependency should never ever be changed unless the version of the artifact is increased. From what I found there is no direct way to force Maven to update the release dependencies because once particular version was published it should stay in a given binary form forever. What you can do is you can go to your local Maven repository and delete suspected dependency. Then Maven will be obliged to reach out to the remote repository and it will retrieve the same version with newer binary changes.

2. There is a compilation error within the project - meaning that someone committed/pushed some code which does not compile. You should check annotations in version control system and ask that person about explanation. This situation may occur rather rarely because every decent project has continuous integration in place and the unlucky committer should've been automatically notified about a mistake s/he had committed.

That's all folks! 

1 comment :