0

We are using GitLab Enterprise Edition 13.12.2-ee on a company-provided Dockermachine runner to build Maven-based projects. They set MAVEN_OPTS to contain environment-specific parameters like Proxy settings. For our build, we need to append MAVEN_OPTS, for example to set -Dmaven.repo.local to enable caching of our local Maven repository. I tried several variants for this in our .gitlab-ci.yml:

build:
  variables:
    MAVEN_OPTS: $MAVEN_OPTS "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
    MAVEN_OPTS: "$MAVEN_OPTS -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
    MAVEN_OPTS: ${MAVEN_OPTS} "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
    MAVEN_OPTS: "${MAVEN_OPTS} -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
    MAVEN_OPTS: $$MAVEN_OPTS "-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"
    MAVEN_OPTS: "$$MAVEN_OPTS -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository"

Of course only one at a time, not all at once. None of them seems to work. Does anyone have a hint, how to accomplish this?

Roland
  • 121
  • 2
  • Have you tried `MAVEN_OPTS: '-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository'`? – danielnelz Jun 10 '21 at 10:45
  • Sure. This overrides the whole MAVEN_OPTS which is not what I want since I lose the aforementioned parameters like proxy settings. – Roland Jun 10 '21 at 11:02
  • ok, but then you could just add additional maven options and not overwrite them at all: `build: variables: ADD_MVN_OPTS: '-Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository'` and run maven like: `script: - mvn $MAVEN_OPTS $ADD_MVN_OPTS clean install` – danielnelz Jun 10 '21 at 11:09
  • No. These would be parameters for the Maven application itself. But MAVEN_OPTS are JVM parameters, so these are some kind of lower level. See https://stackoverflow.com/questions/38955721/maven-opts-vs-mvn-d – Roland Jun 10 '21 at 11:29

0 Answers0