Reputation: 15809
I've got a multi-module Maven project in Eclipse. It has one jar module, "myapp-core", and a bunch of .war modules. The core module depends on some external jars, and the war modules depend on the core.
The problem is that when I build the .war files, all of the dependencies get copied into all the WEB-INF/lib folders, so we have duplicates. The right way to solve the problem, theoretically, is to give the dependencies in myapp-core a scope of "provided". Unfortunately, when I do this all the .war modules get compile errors. And all the transitive dependencies get copied anyway!
How do set it up so the dependencies that are common across wars are excluded?
(I can't exclude all the transitive artifacts one-by-one, unfortunately. There's about 50 of them, and it's an ever-changing list.)
Upvotes: 2
Views: 5058
Reputation: 19
you can exclude and include artifacts using configuration sections
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<!--
Exclude JCL and LOG4J since all logging should go through SLF4J.
Note that we're excluding log4j-<version>.jar but keeping
log4j-over-slf4j-<version>.jar
-->
<packagingExcludes>
WEB-INF/lib/commons-logging-*.jar,
%regex[WEB-INF/lib/log4j-(?!over-slf4j).*.jar]
</packagingExcludes>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
for reference pleases see here
Upvotes: 1
Reputation: 9799
Rather than "provided", you can exclude certain transitive dependencies that are being pulled in by certain artifacts, and allow other dependencies to remain. E.g.,
X -depends-> B1 -depends-> C1
Y -depends-> B2 -depends-> C2 -depends-> D1
Then set up your pom to have X exclude B1. Then you end up with the latest & greatest B and latest C (assuming B2 is a newer version of B1, and C2 is a newer version of C1). Further, you can declare D1 a dependency, or mark it as "provided".
See mvnref-book/dependencies for more examples, and the other stackexchange Q&A here
Upvotes: 1