我在我的 gitlab ci/cd docker 镜像上运行 mvn clean install
并抛出以下错误。
[ERROR] Failed to execute goal on project bootstrap.service: Could not resolve dependencies for project com.sheeft:bootstrap.service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at com.google.firebase:firebase-admin:jar:6.10.0 -> com.google.cloud:google-cloud-firestore:jar:1.9.0 -> com.google.cloud:google-cloud-core-grpc:jar:1.79.0 -> io.grpc:grpc-netty-shaded:jar:1.21.0 -> io.grpc:grpc-core:jar:[1.21.0]: No versions available for io.grpc:grpc-core:jar:[1.21.0] within specified range -> [Help 1]
所以我在我的pom中尝试了以下内容
<?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 http://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.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.sheeft</groupId>
<artifactId>bootstrap.service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Sheeft Bootstrap Service</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
<version>[1.23.0]</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</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>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</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>com.vaadin.external.google</groupId>
<artifactId>android-json</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 2fa -->
<dependency>
<groupId>org.jboss.aerogear</groupId>
<artifactId>aerogear-otp-java</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.inlaks</groupId>
<artifactId>inlaks-util-lib</artifactId>
<version>1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.derby/derby -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20160212</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>6.10.0</version>
<exclusions>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-core</artifactId>
<version>1.23.0</version>
<exclusions>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.23.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
<version>[1.23.0]</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
所以现在的错误有点不同,但很奇怪
[ERROR] Failed to execute goal on project bootstrap.service: Could not resolve dependencies for project com.sheeft:bootstrap.service:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at io.grpc:grpc-core:jar:1.23.0 -> io.grpc:grpc-api:jar:[1.23.0]: No versions available for io.grpc:grpc-api:jar:[1.23.0] within specified range -> [Help 1]
上述错误的奇怪之处在于它实际上下载了依赖项,如下所示
从中心下载:https://repo.maven.apache.org/maven2/io/grpc/grpc-api/1.23.0/grpc-api-1.23.0.pom 从中央下载:https://repo.maven.apache.org/maven2/io/grpc/grpc-api/1.23.0/grpc-api-1.23.0.pom (0 B,0 B/s)
请您参考如下方法:
您明确引用 grpc-api 版本 1.21.1,它可以防止来自相关版本的 grpc-core 1.23 的 transient 依赖负载。为什么你想要它们不同? 如果你想让它们保持这样,你必须从 grpc-core 中排除 grpc-api。
但更简单的处理方法是为 api 和 core 保留一个版本。
Maven 范围语法:https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html
对于核心模块,它只是严格的版本兼容性定义为:
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
<version>[1.23.0]</version>
<scope>compile</scope>
</dependency>