简体   繁体   中英

maven dependency conflict only in eclipse

We have several applications as a number of modules; we've been using NetBeans. I am attempting to move the development to eclipse.

All projects are built with Maven. One of them uses dbunit, and also POI. When I try to compile it in eclipse, it gives me an error for a bad method signature. Neither NetBeans build with maven nor command-line build give me this error.

I discovered that the compiler was attempting to compile using a version of POI older than the one we use. The specific version of POI is designated in compile scope as a dependency for dbunit, according to dbunit's maven repository info. I don't understand why that would pull that version of POI into my compile, since I'm using dbunit, not compiling it.

Nor do I understand why it gets pulled in for eclipse and not for either of the other two compilation operations.

I have seen a number of comments on SO and on the eclipse bug report site about how eclipse uses one classpath only, and that it would be difficult to change and that there are no plans to change.

If that's true, how are other people dealing with this? I can't have the only project in the world (or even in my city) that uses libraries that have compile dependencies that conflict with the project compilation. Is there an m2e patch, or an eclipse workaround, hopefully something that does not involve modifying all 20 pom.xml files?

Compile dependencies are transitive. The Maven2Eclipse plugin uses only one dependency from the tree for a library (probably not the same as Maven does).

To be on the safe side, exclude POI when using dbunit:

<dependency>
  <groupId>org.dbunit</groupId>
  <artifactId>dbunit</artifactId>
  <version>...</version>
  <exclusions>
    <exclusion>
      <groupId>org.apache.poi</groupId>
      <artifactId>poi</artifactId>
    </exclusion>
  </exclusions>
</dependency>

If you use a newer version of dbunit like 2.4.3, the dependency to POI is optional, meaning not transitive.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM