如何使用maven避免类冲突

时间:2012-12-11 04:58:16

标签: java dependencies maven-3 conflict maven-shade-plugin

我使用maven-shade-plugin来构建一个项目,但是,我遇到了一个我无法处理它的问题。两个jar几乎有相同的类,路径相同,aspectjweaver.jar和aspectjrt。 jar,当打包jar时,我得到警告“重复类已存在于......”。我试图使用“重定位”属性重新定位类,但问题是,如何在两个罐子中识别该类?接下来是我的Pom.xml的一部分。                          org.apache.maven.plugins                 行家遮阳帘插件                 1.3.1

            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>

                        <filters>
                            <filter>
                                <artifact>org.aspectj:aspectjrt</artifact>
                                <includes>
                                    <include>*</include>
                                </includes>
                            </filter>
                        </filters>
                        <relocations>
                            <relocation>
                                <pattern>org.aspectj</pattern>
                                <shadedPattern>hide.org.aspectj</shadedPattern>
                            </relocation>
                        </relocations>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>cm.data.DatBoostrap</mainClass>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>

1 个答案:

答案 0 :(得分:0)

您应该使用以下内容从其中一个工件中排除类:

<configuration>
 <filters>
  <filter>
   <artifact>junit:junit</artifact>
   <includes>
    <include>junit/framework/**</include>
    <include>org/junit/**</include>
   </includes>
   <excludes>
    <exclude>org/junit/experimental/**</exclude>
    <exclude>org/junit/runners/**</exclude>
   </excludes>
  </filter>
  <filter>
   <artifact>*:*</artifact>
   <excludes>
    <exclude>META-INF/*.SF</exclude>
    <exclude>META-INF/*.DSA</exclude>
    <exclude>META-INF/*.RSA</exclude>
   </excludes>
  </filter>
 </filters>
</configuration>