我想知道是否可以将自定义 jar 文件部署到现有的 Maven 存储库中。根据习惯,我的意思是,我本地机器上现有的 jar。
因此,我在 gitlab 上有一个项目 test-project ( https://gitlab.com/group/test-project ),它是我使用 gitlab 管道构建和部署的 java 应用程序。在构建阶段,我正在将mvn deploy
包 test-project.jar 推送到 gitlab maven 存储库(https://gitlab.com/group/test-project/-/packages)。
现在,我有一个 dependency.jar 文件,它在我的 pom.xml 中列为依赖项。我想将该文件推送到与我的 test-project.jar 相同的 Maven 存储库中。这里的文档中没有任何相关内容。https://docs.gitlab.com/ee/user/packages/maven_repository
我尝试以此处描述的方式使用 maven-deploy-plugin 推送它http://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html
我收到一个Failed to deploy artifacts: Could not find artifact...
奇怪的错误,因为我正在尝试推送新的工件,当然,它不存在。
我不确定这是否是 GitLab 的问题(我对此表示怀疑),或者我做错了什么,或者我想要的东西是不可能的。
编辑
我能够推送软件包,但问题是我需要从构建运行部署:部署文件,而不是从本地运行。
这将是管道配置
stages:
- build
maven-repo-push:
stage: build
image: maven:3.6.2
variables:
GROUP: "com.example"
ARTIFACT: "myproject"
VERSION: "1.1.1"
REPO_PROJECT_ID: "12345678" #gitlab project ID
script:
- mvn deploy:deploy-file
-DgroupId=$GROUP
-DartifactId=$ARTIFACT
-Dversion=$VERSION
-Dpackaging=jar
-Dfile=$ARTIFACT-$VERSION.jar
-DgeneratePom=false
-DpomFile=$ARTIFACT-$VERSION.pom
-Dfiles=$ARTIFACT-$VERSION-tests.zip
-Dtypes=zip
-Dclassifiers=tests
-DrepositoryId=gitlab-maven
-Durl=https://gitlab.com/api/v4/projects/$REPO_PROJECT_ID/packages/maven
-s settings.xml
when: manual
Run Code Online (Sandbox Code Playgroud)
确保您已使用此配置推送了要推送的文件格式$ARTIFACT-$VERSION.jar
以及
身份验证所需的默认 settings.xml https://docs.gitlab.com/ee/user/packages/maven_repository/#authenticating-with-a-ci-job-token
尽管如此,我的问题仍然存在,是否可以从本地执行此操作
小智 11
您也可以从本地文件系统发布库/jar,只需有一个settings.xml,例如
<settings>
<servers>
<server>
<id>gitlab-maven</id>
<configuration>
<httpHeaders>
<property>
<name>Private-Token</name>
<value>PUT-YOUR-PRIVATE-TOKEN-HERE</value>
</property>
</httpHeaders>
</configuration>
</server>
</servers>
</settings>
Run Code Online (Sandbox Code Playgroud)
或者,如果您想使用组令牌或部署令牌,请确保更新上面的属性名称,记录在此处https://docs.gitlab.com/ee/user/packages/maven_repository/#authenticate-with-a-deploy -maven 中的令牌
然后使用它在 GitLab 的包注册表上发布您的 jar,请记住,您只能发布到项目 api 端点,但您可以使用组端点在本地下载/安装工件
mvn -s settings.xml deploy:deploy-file \
-Durl=https://gitlab.com/api/v4/projects/<PUT-PROJECT-ID-HERE>/packages/maven \
-DrepositoryId=REPOSITORY-ID # has to match the settings.xml server:id \
-Dfile=your-lib.jar \
-DgroupId=your.group.id \
-DartifactId=artifact-name \
-Dversion=1.0 \
-Dpackaging=jar \
-DgeneratePom=false
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7338 次 |
最近记录: |