【问题标题】:How to avoid the class conflict using maven如何使用 maven 避免类冲突
【发布时间】:2015-04-21 04:05:34
【问题描述】:

我用maven-shade-plugin建一个项目,但是遇到一个问题我处理不了。有两个jar几乎有相同的类,路径相同,aspectjweaver.jar和aspectjrt。 jar ,打包 jar 时,我收到警告“重复的类已存在于 ....”。我尝试使用“重定位”属性来重定位类,但问题是,如何重新识别两个 jar 中的类?接下来是我的 Pom.xml 的一部分。 org.apache.maven.plugins maven-shade-插件 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>

【问题讨论】:

  • 抱歉弄错了,应该删除上面的

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


【解决方案1】:

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

<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>

【讨论】:

  • 我们在 pom 中哪里添加
  • 在shade插件的配置中
猜你喜欢
  • 2019-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-02
  • 2018-02-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多