How to define conditional dependencies on a WAR module?

(Silvio Wangler) #1


My WAR module should be as flexible as possible and run against different JDBC drivers. How can I define “conditional” dependencies (in Maven 2/3 I did use profiles and classifiers to achieve the goal)?

E.g. I want to build the war file for MySQL configuration and define a providedRuntime dependency to the mysql JDBC jar. For development I want to build the thing using H2 as a database.

How can I achieve such a thing or how do you handle such a scenario?

Best regards Silvio

(Peter Niederwieser) #2

It should be good enough to declare the H2 JDBC Jar as a ‘providedCompile’ dependency (or ‘providedRuntime’ if you don’t interact with JDBC classes directly). In production, the web container then provides the MySQL Jar.