简体   繁体   English

Maven jar:jar 未收集依赖项

[英]Maven jar:jar not gathering dependencies

I am trying to use semantic-release within a GitLab CI pipeline.我正在尝试在 GitLab CI 管道中使用语义发布。 I have the prepare stage working fine, but the publish stage always fails when I use anything other than mvn jar:jar deploy:deploy , but when i use those commands it deploys a jar that is 3kb big instead of a jar that is 10mb .我的准备阶段工作正常,但是当我使用mvn jar:jar deploy:deploy以外的任何东西时,发布阶段总是失败,但是当我使用这些命令时,它会部署一个3kb 大的 jar 而不是 10mb 的 jar So i can only assume that it is not gathering dependencies.所以我只能假设它没有收集依赖项。 There was a WARNING message about no files being marked for inclusion and the jar being empty.有一条关于没有文件被标记为包含和 jar 为空的WARNING消息。 So I tried to package the project before calling deploy.所以我尝试在调用deploy之前打包项目。 It did not work.这没用。

The pipeline fails with no reason as to why.管道失败,原因不明。 It just show that line as the culprit.它只是将该行显示为罪魁祸首。

commands I have tried:我试过的命令:

mvn clean install
mvn clean package deploy
mvn jar:jar deploy:deploy
mvn clean deploy:deploy
.. you get the idea. 

Here is the prepare section that works:这是有效的准备部分:

verifyConditions:
  - "@semantic-release/changelog"
  - "@semantic-release/gitlab"
  - "@semantic-release/git"
verifyRelease:
  - path: "@semantic-release/exec"
    cmd: echo -e "VERSION=${nextRelease.version}\nNEW_RELEASE=true" > RELEASE.env
prepare:
  - path: "@semantic-release/exec"
    cmd: if [ ! -d ".m2" ]; then mkdir .m2; cd .m2; touch settings.xml; echo $MVN_SETTINGS | base64 -d > 'settings.xml'; cd ..; fi;  mvn versions:set -DnewVersion=${nextRelease.version} -B -gs .m2/settings.xml;
  - "@semantic-release/changelog"

And here is the publish section that only works with jar:jar deploy:deploy but does not create the correct jar.这是仅适用于 jar:jar deploy:deploy 但不创建正确 jar 的发布部分。

publish:
  - "@semantic-release/gitlab"
  - path: "@semantic-release/exec"
    cmd: if [ ! -d ".m2" ]; then mkdir .m2; cd .m2; touch settings.xml; echo $MVN_SETTINGS | base64 -d > 'settings.xml'; cd ..; fi; mvn versions:set -DnewVersion=${nextRelease.version} -DremoveSnapshot=true clean deploy -B -gs .m2/settings.xml;

I'm extremely new to this, and I cannot see why:我对此非常陌生,我不明白为什么:

1) trying clean deploy is causing this to fail and jar:jar deploy:deploy doesn't 2) how I can get semantic-release to create a jar with all dependencies for upload to our repository. 1) 尝试clean deploy导致此失败,而jar:jar deploy:deploy不会 2) 我如何获得语义发布以创建一个包含所有依赖项的 jar 以上传到我们的存储库。

I should note that both Maven Shade plugin and Maven Deploy plugin are present in my pom.我应该注意到 Maven Shade 插件和 Maven Deploy 插件都存在于我的 pom 中。

This is an older run, but they all are formatted like this and tell you nothing about WHY it failed.这是一个较旧的运行,但它们都是这样格式化的,并且没有告诉您失败的原因。 Just that it did:只是它做到了:

  stderr: '/bin/sh: line 1:   425 Killed                  mvn clean deploy -B -gs .m2/settings.xml\n',
  failed: true,
  signal: null,
  cmd: '/bin/sh -c mvn $MAVEN_CLI_OPTS versions:set -DremoveSnapshot; mvn clean deploy -B -gs .m2/settings.xml',
  timedOut: false,
  killed: false,
  pluginName: '@semantic-release/exec' }ERROR: Job failed: command terminated with exit code 1

First of all, for deployment use mvn clean deploy .首先,部署使用mvn clean deploy The other combinations you presented do not produce sensible output.您提供的其他组合不会产生合理的输出。

If you want to package the dependencies into your jar, you need to properly configure the Maven shade plugin (configuring the deploy plugin is usually not necessary).如果要将依赖打包到jar中,则需要正确配置Maven shade插件(通常不需要配置deploy插件)。 Without your pom.xml , I can only guess, but I would say that the error is probably in that configuration.没有您的pom.xml ,我只能猜测,但我会说错误可能出在该配置中。

BTW: Only put the dependencies into the jar if the jar is meant to run standalone.顺便说一句:如果 jar 旨在独立运行,则仅将依赖项放入 jar 中。 If, on the other hand, you write a Java library to be used as dependency, don't do it.另一方面,如果您编写了一个用作依赖项的 Java 库,请不要这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM