-1

Overview

This may be a trivial question or may not be eligible to be here but any suggestion will be helpful.

When a dependency is added to the pom.xml bunch of errors show up while compiling a project into java jar without any code change what so ever

Steps

  • Clone a git repo for the project and execute mvn clean compile

    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.743 s
    [INFO] Finished at: 2018-05-31T22:21:04+00:00
    [INFO] Final Memory: 25M/389M
    [INFO] ------------------------------------------------------------------------
    
  • Add new required dependency to pom.xml of the same project MVN Ref

    <dependency>
        <groupId>org.apache.storm</groupId>
        <artifactId>storm-hive</artifactId>
        <version>1.1.1</version>
    </dependency>
    
  • Now again execute mvn clean compile

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project saavn-storm-lib: Compilation failure: Compilation failure:
    [ERROR] /home/user/backend/storm/storm_lib/src/main/java/com/storm/bolts/Helper.java:[167,57] unreported exception org.json.JSONException; must be caught or declared to be thrown
    
    .
    
    .
    
    .
    
    .
    

    Multiple occurrences of JSONException related error message, followed by

    [ERROR] /home/user/backend/storm/storm_lib/src/main/java/com/storm/bolts/Helper.java:[132,58] cannot find symbol
    [ERROR] symbol:   method unescapeJson(java.lang.String)
    [ERROR] location: class org.apache.commons.lang3.StringEscapeUtils
    

More info

  • pom.xml contains

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.3.2</version>
    </dependency>
    
  • Corresponding dependency is present locally as well

    ls -l ~/.m2/repository/org/apache/commons/commons-lang3/3.3.2/
    
    commons-lang3-3.3.2.jar
    commons-lang3-3.3.2.jar.sha1
    commons-lang3-3.3.2.pom
    commons-lang3-3.3.2.pom.sha1
    _remote.repositories
    
  • This method is deprecated in subsequent releases but it is very much present in this version and it was working so far.

Question

  • Why these were not shown in the first place as they seems to be present already, given no code was modified ?
  • JSONException related errors can be taken care of but why some dependency is suddenly missing and how to rectify that ?
Albatross
  • 669
  • 7
  • 24

1 Answers1

0

Two most likely scenarios:

  1. There was a already a dependency on a different version of storm-hive before you added that dependency. If you go back to the working state (before you added the dependency) and call the Maven goal dependency:list, you might already see a storm-hive in the list.

  2. There is a different dependency in the dependency:list that shares qualified class names with storm-hive. If you have different classes with same names on your classpath, Java just picks one of them and this might lead to strange errors.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • With the pointers above I searched little more and stumbled across [This](https://stackoverflow.com/questions/547805/exclude-all-transitive-dependencies-of-a-single-dependency). This helped in unblocking. But the question remains as to how to efficiently identify dependencies causing problems? I used `dependency : analyse` `dependency : tree` while poking around. – Albatross Jun 01 '18 at 21:20
  • Why do you need exclusions? What do you mean by "dependencies causing problems"? – J Fabian Meier Jun 02 '18 at 18:57
  • I checked for anything conflicting with `storm-hive` but did not find anything. So is it likely that some other packages that are pulled as a result of this particular entry might be creating problems I am facing ? That is what I referred to as _dependencies causing problems_ but what I meant was packages. – Albatross Jun 04 '18 at 21:57
  • Instead excluding as suggested in previous comment, just putting `storm-hive` dependency as the last one in the order while declaring in the `pom.xml` solved the problem. – Albatross Jun 08 '18 at 15:38
  • Probably dependencyManagement would be a better Solution – J Fabian Meier Jun 09 '18 at 15:24