I have a maven POM file for a web service. For one of the dependencies I have to specify several exclusions for jar files that are already kept at a higher-level in the web-application server (accessible to all web-applications, not just this particular one). One example of such exclusion is the JAR containing my JDBC driver.
Example (with fictional details):
<dependency>
<groupId>mygroup</groupId>
<artifactId>myartifact</artifactId>
<version>1.0.0</version>
<exclusions>
<!--The jdbc driver causes hot-deployment issues-->
<exclusion>
<groupId>db.drivers</groupId>
<artifactId>jdbc</artifactId>
</exclusion>
</exclusions>
</dependency>
The problem I am encountering is that I need the JDBC driver for my tests. My tests currently fail since they cannot load the JDBC driver.
How can I configure the POM so that the excluded parts are accessible to my tests, but do not get included into my WAR file?
Update: I cannot make changes to the POM for mygroup.myartifact since this it is being depended on by many other projects, and this exclusion requirement is unique for my project.
Update 2: It seems I did a poor job of phrasing this question. Lars's solution below is perfect for one exclusion (as the example shows), however in my real scenario I have multiple exclusions, and adding additional dependencies for each seems smelly. The solution that seems to work is to set the scope of the shown dependency to compile and then create a second dependency the same artifact (mygroup.myartifact) with no exclusions and the scope set to test. Since Lars both answered my poorly phrased question correctly, as well as led me in the direction of the actual solution, I will mark his reply as the answer.