我有一个java-spring应用程序,在不同的存储库中有两个maven依赖项,但在同一组中。我使用gitlab-ci在2个项目包注册表中部署jar,但我无法检索它们(我只能使用一个依赖项,在spring应用程序pom中设置其项目repo)。.对于这两个依赖项,我编写了相同的ci-settings.xm
l:
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Job-Token</name>
<value>${env.CI_JOB_TOKEN}</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
与相同的gitlab-ci.yml
:
deploy:
image: maven:3.6-jdk-11
script:
- 'mvn deploy -s ci_settings.xml'
only:
- master
在第一个依赖项(sp1)的pom.xml中:
<groupId>ch.myCompany.dep</groupId>
<artifactId>sp_1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/groups/GROUP_ID/-/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/SP1_REPO_ID/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/SP1_REPO_ID/packages/maven</url>
</snapshotRepository>
</distributionManagement>
在第2个依赖项(sp2)的pom.xml中我有:
<groupId>ch.myCompany.dep</groupId>
<artifactId>sp_2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/groups/GROUP_ID/-/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/SP2_REPO_ID/packages/maven</url>
</repository>
<snapshotRepository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/SP2_REPO_ID/packages/maven</url>
</snapshotRepository>
</distributionManagement>
在spring应用程序中,我将两个工件设置为依赖项,但我无法检索它们。这是pom.xml的一部分:
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>ch.myCompany.dep</groupId>
<artifactId>sp_service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sp_service</name>
<description>Service Layer for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<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.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ch.myCompany.dep</groupId>
<artifactId>sp_1</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>ch.myCompany.dep</groupId>
<artifactId>sp_2</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>gitlab-maven</id>
<url>https://gitlab.com/api/v4/projects/GROUP_ID/packages/maven</url>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
在依赖项的pom.xmldistributionManagement
部分,您正在使用正确的url:
<url>https://gitlab.com/api/v4/groups/GROUP_ID/-/packages/maven</url>
但是,在spring应用程序pom.xmlrepositories
部分中,url是不正确的:
<url>https://gitlab.com/api/v4/projects/GROUP_ID/packages/maven</url>
在GROUP_ID
和packages
之间缺少/-/
。