我想将 JAR 上传到 GitLab 包注册表

Ern*_*ert 5 gradle maven gitlab

我有一个预构建的 JAR 文件,我想将其上传到 GitLab 包注册表中,以便在执行构建时可以使用它。

这是我第一次使用 Maven 并在这里上传所以新手警报!

在我的 GitLab 项目中,我确实看到有一个标题为“包注册表”的部分。我认为我需要将其上传到那里。

我发现以下命令可能会解决问题:

mvn deploy:deploy-file -DgroupId=com.acme.group -DartifactId=project-name \
-Dversion=1.2.3 -Dpackaging=jar -Dfile="test.jar" \
-Durl=https://gitlab-np-services.com/Ernie/ernie-sandbox-1/-/packages
-DrepositoryId=project-name 
Run Code Online (Sandbox Code Playgroud)

我不知道要为“DrepositoryId”、“DartifactId”输入什么。我在输入内容中假设的另一个字段。

我如何知道在这些字段中放置什么?

我运行它并得到以下信息:

Uploading to remote-repository: https://gitlab-np.services.com/Ernie/ernie-sandbox-1/-/packages/com/acme/group/project-name/1.2.3/project-name-1.2.3.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.793 s
[INFO] Finished at: 2021-06-01T15:51:09-05:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file (default-cli) on project standalone-pom: Failed to deploy artifacts: Could not transfer artifact com.acme.group:project-name:jar:1.2.3 from/to remote-repository (https://gitlab-np-services.com/Ernie/ernie-sandbox-1/-/packages): transfer failed for https://gitlab-np.services.com/Ernie/ernie-sandbox-1/-/packages/com/acme/group/project-name/1.2.3/project-name-1.2.3.jar, status: 422 Unprocessable Entity -> [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/MojoExecutionException
vanduyne-16mb:ernie-sandbox-1 vanduyer$ -DrepositoryId=project-name 
bash: -DrepositoryId=project-name: command not found
Perhaps I need to allow permissions to upload to that location in GitLab - which I have no clue how to do.
Run Code Online (Sandbox Code Playgroud)

那是我应该上传到的地方吗?

我尝试查看 Maven 站点和其他站点以获取有关如何执行此操作的帮助,但我找不到为新手解释这一点的内容。

谢谢你的帮助!

Rez*_*our 1

有几个问题我将在下面列出。

  • 首先,您\在第三行末尾缺少一个。因此,-DrepositoryId=project-name参数没有传递给mvn deploy命令。

  • 接下来,您需要决定要部署哪个级别的工件?您可以在 Gitlab 的官方文档( GitLab endpoint for Maven packages )上阅读有关级别的更多信息。这些地址通向,但您在 URL 中/packages/maven缺少令牌。/maven( https://gitlab-np-services.com/Ernie/ernie-sandbox-1/-/packages)

  • repositoryId如果您没有server在文件中配置任何内容,则不需要传递 a settings.xml。如果您配置了它,那么您可以使用定义的 Id。因此,Maven 可以使用文件中的配置settings.xmlrepositoryId更多关于Maven的官方文档可以阅读: repositoryId

  • 和参数是定义如何从存储库导入工件的必需参数groupId。我建议您使用工件文件artifactId中配置的相同的groupId和artifactId 。pom.xml如果您使用 部署包groupId=com.groupartifactId=artifact-id则可以将工件导入到您的项目中,如下所示:

     <dependencies>
         <dependency>
             <groupId>com.group</groupId>
             <artifactId>artifact-id</artifactId>
             <version>...</version>
         </dependency>
         ...
     </dependencies>
    
    Run Code Online (Sandbox Code Playgroud)

我建议阅读有关部署到 Gitlab 的 Maven 存储库的更多信息,因为您还必须配置身份验证部分:Package Repository 中的 Maven 包