J Fabian Meier
J Fabian Meier

Reputation: 35843

Filtering out provided dependencies for a war

If I build a war for a specific platform (e.g. Wildfly), I need to filter out dependencies that are already provided by the platform.

Up to now, we do this by using a special BOM that lists all the provided dependencies with scope provided. Alternatively, one could also use the Maven war plugin to exclude the dependencies when building the war.

What is the preferred way?

Upvotes: 0

Views: 166

Answers (1)

seenukarthi
seenukarthi

Reputation: 8682

Provided scope is there for this specific reason.

From maven documentation

provided

This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

The transitive dependencies of the provided scope will be also be in provided scope unless it is explicitly added in compile scope. If exclution is used it may cause jar conflict unless those jar are also excluded.

Also provided scope works with other packaging like ear

Upvotes: 1

Related Questions