9

当我使用程序集插件时,我得到了一个意外版本的依赖项(1.5.8),但没有其他地方。在我的 pom 中,我有:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.0</version>
    </dependency>

当我运行dependency:treeordependency:list时,我看到了正确的版本并且只有正确的版本。当我签入 Eclipse 时,我只看到正确的版本。

在我的 assembly.xml 我有:

<dependencySets>
    <dependencySet>
        <outputDirectory>lib</outputDirectory>
    </dependencySet>
</dependencySets>

在生成的 zip 中,我得到 slf4j-log4j12-1.5.8.jar。不知道这是从哪里来的。有什么帮助吗?

使用 Maven 3.0.4。

4

2 回答 2

10

这是由于“错误”的程序集插件版本 (2.2-beta-5)。我的 pom.xml 没有指定插件版本。当我将其明确标记为 2.4(或您阅读本文时的最新版本!)时,插件提取了正确的依赖项。

经验教训 - 如果您在构建中收到以下警告:

[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-whatever-plugin is missing
It is highly recommended to fix these problems because they threaten the stability of your build.

.. 修理它!

于 2012-12-13T14:59:26.247 回答
4
  1. 您可以尝试从您的 maven 存储库中删除错误的 JAR (slf4j-log4j12-1.5.8.jar) 并在那里添加正确的 JAR (slf4j-log4j12-1.6.0.jar)。--offline然后使用开关运行您的构建。在 maven 尝试获取错误 JAR 的那一刻,构建将失败,并且 maven 将向您展示它试图从什么传递依赖中获取它。然后你用这个将它从传递依赖中排除:

    <exclusions>
      <exclusion>
        <artifactId>slf4j-api</artifactId>
        <groupId>slf4j-log4j12</groupId>
      </exclusion>
    </exclusions>
    
  2. 检查您获得的 JAR 是否具有正确的 groupId。有些人会出于愚蠢和邪恶的特殊目的创建常见 JAR 的副本,这可能会使 maven 感到困惑。特别是,检查您是否没有得到org.jboss.resteasy:slf4j-log4j12替代。您可以使用 maven-enforcer-plugin 禁止不需要的依赖项,如下所示:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-enforcer-plugin</artifactId>
      <version>1.0</version>
      <executions>
        <execution>
          <id>enforce-banned-dependencies</id>
          <goals>
             <goal>enforce</goal>
          </goals>
          <configuration>
            <rules>
              <bannedDependencies>
                <excludes>
                  <exclude>org.slf4j:slf4j-log4j12:1.5.8</exclude> <!-- Wrong version, dude! -->
                  <exclude>commons-logging:*</exclude> <!-- Worst, stupidest, lamest logging framework ever! -->
                  <exclude>org.jboss.resteasy:slf4j-simple</exclude> <!-- Evil JAR duplication. -->
                  <exclude>org.jboss.resteasy:slf4j-api</exclude> <!-- Evil JAR duplication. -->
                  <exclude>org.jboss.resteasy:slf4j-log4j12</exclude> <!-- Evil JAR duplication. -->
                  <exclude>org.jboss.resteasy:jackson-core-asl</exclude> <!-- Evil JAR duplication. -->
                  <exclude>org.jboss.resteasy:jackson-mapper-asl</exclude> <!-- Evil JAR duplication. -->
                  <exclude>org.jboss.resteasy:jackson-core-lgpl</exclude> <!-- Evil JAR duplication. -->
                  <exclude>org.jboss.resteasy:jackson-mapper-lgpl</exclude> <!-- Evil JAR duplication. -->
                  <exclude>org.codehaus.jackson:jackson-core-lgpl</exclude> <!-- Two distinct packages for the exact same thing always creates conflicts. We want the ASL one. -->
                  <exclude>org.codehaus.jackson:jackson-mapper-lgpl</exclude> <!-- Two distinct packages for the exact same thing always creates conflicts. We want the ASL one. -->
                  <exclude>velocity-tools:velocity-tools</exclude> <!-- Was renamed. -->
                  <exclude>velocity:velocity</exclude> <!-- Was renamed. -->
                  <exclude>struts:struts</exclude> <!-- Was renamed. -->
                  <exclude>javassist:javassist</exclude> <!-- Was renamed. -->
                  <exclude>axis:*</exclude> <!-- Was renamed to org.apache.axis:* and wsdl4j:wsdl4j . -->
                  <exclude>commons-beanutils:commons-beanutils-core</exclude> <!-- Redundant package. -->
                  <exclude>xpp3:xpp3_min</exclude> <!-- Redundant package. -->
                  <exclude>xml-apis:xml-apis:2.0.0</exclude> <!-- Bad package, for some strange reason 2.0.x is inferior to 1.4.x. -->
                  <exclude>xml-apis:xml-apis:2.0.2</exclude> <!-- Bad package, for some strange reason 2.0.x is inferior to 1.4.x. -->
                  <exclude>quartz:quartz</exclude> <!-- Was renamed. -->
                </excludes>
              </bannedDependencies>
            </rules>
          </configuration>
        </execution>
      </executions>
    </plugin>
    
于 2012-12-13T00:06:45.057 回答