【问题标题】:Maven download unspecified jar file in pomMaven在pom中下载未指定的jar文件
【发布时间】:2019-01-13 01:11:35
【问题描述】:

我使用 maven 作为项目依赖管理工具。我有一个项目,我将 xml 文件放在具有特定版本的 maven 中,但我也下载了旧版本。

这里我想通过这个下载spring-core 5.0.8

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>5.0.8.RELEASE</version>
</dependency>

它还下载了 3.0.6.RELEASE 版本的 spring-core。如何跳过这种依赖? ,这是我的老pom,这个也是下载3.0.6的。

这是我的 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.guru.gurusahakari</groupId>
<artifactId>gurusahakari</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<url>http://maven.apache.org</url>



<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <tomee.version>2.0.0-SNAPSHOT</tomee.version>
    <version.shrinkwrap.resolver>2.0.0</version.shrinkwrap.resolver>
    <javaassist.version>3.21.0-GA</javaassist.version>
</properties>

<repositories>
    <repository>
        <id>apache-m2-snapshot</id>
        <name>Apache Snapshot Repository</name>
        <url>https://repository.apache.org/content/groups/snapshots</url>
    </repository>
</repositories>


<build>
    <sourceDirectory>src</sourceDirectory>
    <!-- <finalName>gurusahakari</finalName> -->
    <defaultGoal>install</defaultGoal>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <id>copy-test-libs</id>
                    <phase>process-test-resources</phase>
                    <configuration>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax.servlet</groupId>
                                <artifactId>jstl</artifactId>
                                <version>1.2</version>
                            </artifactItem>
                            <artifactItem>
                                <groupId>taglibs</groupId>
                                <artifactId>standard</artifactId>
                                <version>1.1.2</version>
                            </artifactItem>
                        </artifactItems>
                        <outputDirectory>
                            ${project.build.directory}/test-libs
                        </outputDirectory>
                        <stripVersion>true</stripVersion>
                    </configuration>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <reuseForks>false</reuseForks> <!-- otherwise openejb embedded and tomee embedded shares the same context 
                    and EJBContainer is broken -->
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <configuration>
                <configuration>
                    <wtpapplicationxml>true</wtpapplicationxml>
                    <wtpversion>2.0</wtpversion>
                </configuration>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.aries.blueprint</groupId>
            <artifactId>blueprint-maven-plugin</artifactId>
            <version>1.4.0</version>
            <configuration>
                <scanPaths>
                    <scanPath>org.opendaylight</scanPath>
                </scanPaths>
            </configuration>
            <dependencies>
                <dependency>
                    <!-- https://stackoverflow.com/questions/38825386/blueprint-maven-plugin-runtimeexception -->
                    <groupId>org.apache.xbean</groupId>
                    <artifactId>xbean-finder-shaded</artifactId>
                    <version>4.5</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <goals>
                        <goal>blueprint-generate</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.openejb.maven</groupId>
            <artifactId>tomee-maven-plugin</artifactId>
            <version>2.0.0-SNAPSHOT</version>
            <configuration>
                <tomeeClassifier>plus</tomeeClassifier>
                <args>-Xmx512m -XX:PermSize=256m</args>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.7</version>
    </dependency>
    <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>1.9.7</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>


    <!-- validation jar -->
    <!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
    <dependency>
        <groupId>javax.validation</groupId>
        <artifactId>validation-api</artifactId>
        <version>2.0.1.Final</version>
    </dependency>


    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>4.0.2.GA</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.apache.bval/bval-jsr303 -->
    <dependency>
        <groupId>org.apache.bval</groupId>
        <artifactId>bval-jsr303</artifactId>
        <version>0.5</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.springframework.session/spring-session -->
    <dependency>
        <groupId>org.springframework.session</groupId>
        <artifactId>spring-session</artifactId>
        <version>1.0.0.RELEASE</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/org.springframework/spring-context-support -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>4.3.8.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports -->
    <dependency>
        <groupId>net.sf.jasperreports</groupId>
        <artifactId>jasperreports</artifactId>
        <version>6.1.0</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.3.8.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.3.8.RELEASE</version>
    </dependency>


    <!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>4.0.1</version>
        <scope>provided</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
    <dependency>
        <groupId>commons-codec</groupId>
        <artifactId>commons-codec</artifactId>
        <version>1.9</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/com.sun.xml.messaging.saaj/saaj-impl -->
    <dependency>
        <groupId>com.sun.xml.messaging.saaj</groupId>
        <artifactId>saaj-impl</artifactId>
        <version>1.3.18</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.11</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <!-- jackson data biending -->
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.5.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.5.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.5.0</version>
    </dependency>

    <!-- Apache Commons FileUpload -->
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.3.1</version>
    </dependency>

    <!-- Apache Commons IO -->
    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.4</version>
    </dependency>


    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.json/json -->
    <dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20160810</version>
    </dependency>
</dependencies>

这里是 mvn 依赖的结果:tree -Dverbose -Dincludes=spring-core.

[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.guru.gurusahakari:gurusahakari:war:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: junit:junit:jar -> duplicate declaration of version 3.8.1 @ line 284, column 15
[WARNING]  
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
 [WARNING] 
 [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
 [WARNING] 
  [INFO]                                                                         
   [INFO] ------------------------------------------------------------------------
   [INFO] Building gurusahakari 0.0.1-SNAPSHOT
   [INFO] ------------------------------------------------------------------------
    [INFO] 
   [INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ gurusahakari ---
     [INFO] ------------------------------------------------------------------------
   [INFO] BUILD SUCCESS
   [INFO] ------------------------------------------------------------------------
   [INFO] Total time: 5.987 s
   [INFO] Finished at: 2018-08-15T09:59:09+05:45
    [INFO] Final Memory: 11M/158M
    [INFO] ------------------------------------------------------------------------

【问题讨论】:

  • 没有机会
  • 显然,是的,我也很困惑。可能是其他进程触发下载
  • 但是不会影响你的项目编译吧?
  • 当然。另外,我对编译不感兴趣。
  • 运行mvn dependency:tree时显示哪个版本已使用

标签: jakarta-ee jar maven-2


【解决方案1】:

我在开发过程中多次收到此错误。 我通过下载jar并在外部添加来修复它,如下所述。

步骤:

  1. 您在 google 上搜索“*.jar maven dependency”或直接前往 maven 依赖项网站并搜索 jar(将 * 替换为您所需的 jar 名称)
  2. 从maven依赖下载jar
  3. 右键项目并点击属性
  4. 选择左侧的“Java Build Path”,然后选择“Libraries”选项卡。现在,点击“添加外部 JARS...”按钮
  5. 找到并选择你下载的jar文件,然后点击“打开”
  6. 最后,单击“确定”关闭对话框。如果打开项目文件夹时,您会看到一个名为“Referenced Libraries”的项目,并且在展开此项目时,您会看到列出的 jar 文件,那么您就会知道一切正常。

【讨论】:

    【解决方案2】:

    我在使用 Maven 时遇到了一些与此类似的奇怪情况,我解决了它删除存储库文件夹 (%user-folder%/.m2/repository) 并再次执行 clean install。有时,带有错误或过时 pom.xml 文件的项目工件的早期版本可能会导致使用 maven 依赖项解析时出现不良行为。

    如果您使用像 IntelliJ IDEA 这样的 IDE(也许 Eclipse 也可以这样工作),请记住它维护自己的工件缓存。所以你也可以尝试在命令提示符下执行clean install 来丢弃东西。

    【讨论】:

      【解决方案3】:

      为了更加自信,我需要看看你的 pom.xml。

      但是有一种官方的方法可以处理这种情况。只需在你的 pom 中添加如下标签:

      <!-- Your actual dependencies -->
      <dependencies>
         <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
         </dependency>
      </dependencies>
      
      <!-- Constraints you put on your direct and transitive dependencies -->
      <dependencyManagement>
         <dependencies>
            <dependency>
               <groupId>org.springframework</groupId>
               <artifactId>spring-core</artifactId>
               <version>5.0.8.RELEASE</version>
            </dependency>
         </dependencies>
      </dependencyManagement>
      

      这将覆盖依赖项以使用此特定版本。

      【讨论】:

      • 现在,maven 里面没有 jar 文件。你知道这是什么原因吗?
      • 和整个项目的错误。它不接受自动装配和控制器等注释。
      • 内部看起来像依赖,&lt;dependencyManagement&gt;&lt;/dependencyManagement&gt; 无法导入。它在移动到&lt;dependencyManagement&gt;&lt;/dependencyManagement&gt; 时出现错误。
      • 亲爱的 Parlad,我忘了包含正确的标签 dependencyManagement -> dependencies -> dependency。您面临的问题可能是因为您有一个或多个依赖项,这些依赖项在不同版本的 spring 中具有依赖关系。最好的方法是使用相同版本的 spring 重建所有依赖项。您也可以尝试打印所有依赖层次结构的 mvn dependency:tree。
      • 我已经这么说了,这里 pom 没有给出任何错误,但是 jar 文件似乎是空的,并且整个项目都出现错误
      【解决方案4】:
      Try like this
      <!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
           <dependency>
              <groupId>org.springframework</groupId>
              <artifactId>spring-core</artifactId>
              <version>5.0.8.RELEASE</version>
          </dependency>
      it should work fine                                                                     
      

      【讨论】:

      • 具体版本,也应该是最新版本,可以解决大部分问题
      • 他无法删除不存在的东西。
      【解决方案5】:

      我想你需要了解为什么 3.0.6 版本的 spring-core 被拉下。

      可能对它有一些传递依赖 - 看看你是否可以通过以下方式找到它:
      mvn dependency:tree -Dverbose -Dincludes=spring-core

      一旦你找到它,你可以使用依赖排除来阻止它被下载,见这个:
      Dependency Exclusions

      例如:

      <dependency>
          <groupId>org.xyz</groupId>
          <artifactId>xyz</artifactId>
          <version>${xyz.version}</version>
          <exclusions>
              <exclusion>
                  <groupId>org.springframework</groupId>
                  <artifactId>spring-core</artifactId>
              </exclusion>
          </exclusions>
      </dependency>
      

      其中 xyz 是对旧 Spring 版本具有传递依赖的工件。

      【讨论】:

      • 我应该在此处为 spring core 4.3.8 添加 false 吗?
      • 不确定您是否需要,请参阅我在帖子中放置的示例 - 您是否发现对 3.0.6 的传递依赖?
      • 实际上不是。我发布了 mvn 依赖项:tree -Dverbose -Dincludes=spring-cor 结果。我没有看到任何具体的。
      【解决方案6】:

      解决这类问题的简单方法是使用像 eclipse 这样的图形工具。(即)

      • 打开依赖管理的水龙头。

      • 过滤、分析和检查不适用的依赖项

      • 删除不需要的依赖项。

      它将为您节省大量的谷歌搜索和时间。

      【讨论】:

        猜你喜欢
        • 2017-07-21
        • 2011-12-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-06-06
        • 2013-03-27
        • 1970-01-01
        • 2012-04-04
        相关资源
        最近更新 更多