【问题标题】:Problem when adding a dependency to maven向maven添加依赖项时出现问题
【发布时间】:2020-10-06 08:46:25
【问题描述】:

我有一个非常基本的 springboot 项目,它有以下 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>



    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

我要添加这个依赖:https://search.maven.org/artifact/org.apache.hive/hive-jdbc/3.1.2/jar

所以我在依赖项中添加了:

<dependency>
  <groupId>org.apache.hive</groupId>
  <artifactId>hive-jdbc</artifactId>
  <version>3.1.2</version>
</dependency>

但是,当我在我的 pom.xml 中有这个时,我有以下错误:

在解决构建路径错误之前无法构建项目

容器“Maven 依赖项”引用了不存在的库 '/home/hduser/.m2/repository/jdk/tools/jdk.tools/1.6/jdk.tools-1.6.jar'

缺少工件 jdk.tools:jdk.tools:jar:1.6

我使用的是 java 11,我的 IDE 以及 JAVA_HOME 设置为 java 11。

我该如何解决这个问题?


编辑 1:

mvn clean package


------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.454 s
[INFO] Finished at: 2020-10-06T10:51:20+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project dataanalytics: Could not resolve dependencies for project com.bla:dataanalytics:jar:0.0.1-SNAPSHOT: Could not find artifact jdk.tools:jdk.tools:jar:1.6 at specified path /usr/lib/jvm/java-11-openjdk-amd64/../lib/tools.jar -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

【问题讨论】:

  • 请使用mvn clean package 运行构建并报告结果。
  • @JFabianMeier 根据您的要求更新了答案。

标签: java spring-boot maven pom.xml


【解决方案1】:

解释错误信息

在指定路径找不到工件 jdk.tools:jdk.tools:jar:1.6 /usr/lib/jvm/java-11-openjdk-amd64/../lib/tools.jar

tools.jar 文件由 JDK 提供 - 看起来 1.6 是从包含的依赖项中引用的 - 建议您明确排除它:

<dependency>
  <groupId>org.apache.hive</groupId>
  <artifactId>hive-jdbc</artifactId>
  <version>3.1.2</version>
  <exclusions>
    <exclusion>
      <artifactId>jdk.tools</artifactId>
      <groupId>jdk.tools</groupId>
    </exclusion>
  </exclusions>

</dependency>

【讨论】:

  • 应该注意的是,使用此选项,您将无法访问依赖于排除工件的功能,这可能是可取的,也可能不是可取的或可接受的。一般来说,排除应该是最后的手段。
猜你喜欢
  • 1970-01-01
  • 2013-03-21
  • 2017-03-07
  • 2021-12-08
  • 2020-01-20
  • 2015-08-01
  • 1970-01-01
  • 2020-07-05
  • 1970-01-01
相关资源
最近更新 更多