[英]How to deploy private jar to gitlab Maven repository
我想知道是否可以将自定义 jar 文件部署到现有的 maven 存储库中。 自定义,我的意思是,我自己的本地机器上现有的 jar。
因此,我在 gitlab ( 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 的问题(我对此表示怀疑)或者我做错了什么,或者我想要的是不可能的。
编辑
我能够推送包,但问题是我需要从构建中运行 deploy:deploy-file,而不是从我的本地运行。
这将是管道配置
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
确保使用此配置推送要推送的文件,格式$ARTIFACT-$VERSION.jar
和
认证所需的默认 settings.xml https://docs.gitlab.com/ee/user/packages/maven_repository/#authenticating-with-a-ci-job-token
尽管如此,我的问题仍然存在,是否可以从本地执行此操作
您也可以从本地文件系统发布库/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>
或者,如果您想使用组令牌或部署令牌,请确保更新上面的属性名称,记录在此处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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.