I have a .jar we have developed in-house. It is built using maven. It has a dependency, commons-codec, that is provided from the maven central repository.
.jar .pom dependency ("myjar"):
<packaging>jar</packaging>
...
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
...
.war .pom dependency:
<packaging>war</packaging>
...
<dependency>
<groupId>com.myco.mydiv</groupId>
<artifactId>myjar</artifactId>
<version>1.5.54</version>
</dependency>
....
I can build and test this jar without issue. When the jar is included as a dependency in a .war, it builds without problem, but at run time, the external dependency for commons-codec produces a class def not found exception.
I tried changing the scope for commons-codec in the .jar .pom to 'compile' but this did not help.
I can fix this by adding the commons-codec dependency to the .war .pom, but this is not the right way to fix it (I think) as it requires all projects using the .jar to know about this dependency and include it likewise. I could also include the external .jar in the WEB-INF/lib to solve this, but it also seems like the incorrect approach.
What is the best way to handle this? Why is the common-codec dependency not visible at run time for the .war?
This conversation seems to touch on a similar issue: https://github.com/ReactiveX/RxNetty/issues/292
And so I wonder if there is a right way to handle this with nested dependencies.
But I just noticed this answer, which seems to show the right way to do this: https://stackoverflow.com/a/98743/2266428
jar-with-dependencies via the maven-assembly-plugin seems to solve the problem but at the expense of a very large .jar (6 MB in my case).