0

I am trying to use semantic-release within a GitLab CI pipeline. 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. 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. So I tried to package the project before calling 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.

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.

I should note that both Maven Shade plugin and Maven Deploy plugin are present in my 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
  • As JF Maier already stated you seemed to misunderstand/misuse Maven here...If you like to create a jar which contains also dependencies you should use maven-shade-pugin and configure that correctly in your maven build first before you go to Gitlab ci ...furthermore `mvn clean deploy` should the things which are needed...Apart from that you writing something is failing but you don't have posted any kind of information related to that... – khmarbaise Dec 16 '19 at 19:46
  • Hello. Yep, I have maven shade plugin working correctly already. I can mvn clean install and mvn clean deploy locally and it builds a jar with all dependencies. BUT in git lab ci, mvn clean deploy fails. mvn clean install fails. mvn clean package fails, etc. The shade plugin I have is taken directly from maven. It was copied exactly and works, just not in the gitlab ci. –  Dec 16 '19 at 19:50
  • As I mentioned before whtat is the exact error message best with log output ...otherwise it's impossible to even guess what might be wrong.. – khmarbaise Dec 16 '19 at 20:17
  • I have posted it above. It tells me nothing. –  Dec 16 '19 at 20:22
  • I have just found this in the logs right. I'm using jar:jar deploy:deploy (the method that does not produce the shaded jar). [WARNING] JAR will be empty - no content was marked for inclusion! –  Dec 16 '19 at 20:29
  • Please note that Maven calls like `jar:jar deploy:deploy` don't make sense. – J Fabian Meier Dec 16 '19 at 20:41
  • just ran with mvn deploy and if failed.. no explanation why. jar:jar deploy:deploy does not fail, but the behavior is not what I want. –  Dec 16 '19 at 20:51
  • Could you maybe write a new question (or completely rewrite this one)? I would leave out all the stuff with `jar:jar` because calling `jar:jar` will never work. Instead I would explain in more detail what you call from gitlab ci and what the error output is that you get. – J Fabian Meier Dec 17 '19 at 07:40

1 Answers1

1

First of all, for deployment use 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). Without your pom.xml, I can only guess, but I would say that the error is probably in that configuration.

BTW: Only put the dependencies into the jar if the jar is meant to run standalone. If, on the other hand, you write a Java library to be used as dependency, don't do it.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Hello., I understand the difference between deploy and install. install = into local repo. deploy = into remote repo. The problems is that deploy does not work in the gitlab ci pipeline. That is what I'm trying to figure out. mvn clean install and mvn clean deploy all work locally and build the jar as intended. –  Dec 16 '19 at 19:52
  • Running `versions:set` and `clean deploy` in the same `mvn` run is unlikely to work. You need to separate `mvn` runs for that, so first call `mvn versions:set` with the appropriate parameters and then `mvn clean deploy`. – J Fabian Meier Dec 16 '19 at 20:07