Override parent pom dependency

2019-08-07 03:52发布

问题:

I made a simple EAR project with maven and wildfly, but I have some problems with obsolete dependencies.

Project structure is like:

Project
  --EarProject
  --BaseProject
  --WarProject
  --EjbProject

In parent Project's pom there is dependency:

<dependency>
    <groupId>org.wildfly.bom</groupId>
    <artifactId>jboss-javaee-7.0-with-tools</artifactId>
    <version>${version.jboss.bom}</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

And in BaseProject's pom I use Selenium:

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-remote-driver</artifactId>
</dependency>

The problem is that in BaseProject Maven libraries I see older versions of Selenium (ie. selenium-firefox-driver 2.40.0 instead of newer 2.44.0) and because of bugs in 2.40.0 my app does not work corectly. I tried to add:

<version>2.44.0</version>

in BaseProject's pom, but I got warning like

Overriding managed version 2.40.0 for selenium-remote-driver

and it does not work.

How can I override version of dependency from parent's pom or exclude selenium from jboss-javaee-7.0-with-tools dependency?

回答1:

How can I override version of dependency from parent's pom

The "Overriding managed version 2.40.0 for selenium-remote-driver" warning is a just a m2e warning not a Maven warning. With your code, you are correctly overriding the version of the dependency of the parent's pom. See this bug at Eclipse site for m2e about this warning. You can assert that by looking at the dependency tree (in Eclipse or with the mvn dependency:tree command)

or exclude selenium from jboss-javaee-7.0-with-tools dependency?

You can do that with the exclusions tag. It is a tag where you specify each groupId and artifactId that you want to exclude from the transitive dependencies resolved by Maven.