Exclude classes from a dependency in Maven

后端 未结 2 1409
自闭症患者
自闭症患者 2020-12-10 04:06

I have a project which depends on an artifact which is controlled by a supplier. This artifact contains some classes that I depend on, and some which are older and causing p

2条回答
  •  渐次进展
    2020-12-10 04:46

    If you are using Maven 2.0.9+, then just put your class in a jar and declare it as dependency before the artifact from your supplier. As mentioned by @Peter, Maven uses the pom order for the classpath since Maven 2.0.9 (see MNG-1412 / MNG-3111).

    If for whatever reason you're not satisfied with this solution, then you could use the Maven Dependency Plugin to unpack the dependency in target/classes (which should be on the compile classpath) using dependency:unpack with some excludes (see Unpacking specific artifacts). I wouldn't even try to repackage it, this will introduce useless complexity (replacing the old jar with the new one on the compile classpath won't be trivial, if feasible).

提交回复
热议问题