我有一个预构建的 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
我不知道为“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.
那是我应该上传的地方吗?
我曾尝试查看 Maven 站点和其他站点以获取有关如何执行此操作的帮助,但我找不到可以为新手解释这一点的内容。
感谢您的帮助!
答案 0 :(得分:0)
我将在下面列出一些问题。
首先,您在第三行的末尾缺少 \
。因此,-DrepositoryId=project-name
参数不会传递给 mvn deploy
命令。
接下来,您需要决定要部署工件的级别?您可以在 Gitlab 的官方文档 (GitLab endpoint for Maven packages) 上阅读有关级别的更多信息。这些地址指向 /packages/maven
,但 URL 中缺少 /maven
标记。 (https://gitlab-np-services.com/Ernie/ernie-sandbox-1/-/packages
)
如果您没有在 repositoryId
文件中配置任何 server
,则不需要传递 settings.xml
。如果您配置了它,那么您可以使用定义的 Id。因此,Maven 可以使用 settings.xml
文件中的配置。您可以在 Maven 的官方文档中阅读有关 repositoryId
的更多信息:repositoryId
groupId
和 artifactId
参数是定义如何从存储库导入工件的必需参数。我建议您使用在工件的 pom.xml
文件中配置的相同 groupId 和 artifactId。如果您使用 groupId=com.group
和 artifactId=artifact-id
部署包,那么您可以像这样将工件导入到您的项目中:
<dependencies>
<dependency>
<groupId>com.group</groupId>
<artifactId>artifact-id</artifactId>
<version>...</version>
</dependency>
...
</dependencies>
我建议阅读有关部署到 Gitlab 的 Maven 存储库的更多信息,因为您还必须配置身份验证部分:Maven packages in the Package Repository