Maven: Define SuperPOM property project.build.directory over command line

Viewed 84

I am building my maven project with GitLab CI on a docker file. I would like to configure my pipeline with a "compile" stage and a "test" stage. To be able to do that, I need to set the property project.build.directory, which is defined in the maven super POM, to the docker cache so the compiled artefact does not get lost between the jobs.

project.build.directory is a predefined maven property. Therefore I would think that I am able define it with the CL parameter -Dproject.build.directory=anotherDir. This somehow does not work and my project still gets built to the default directory target.

If I modify my POM with

<properties>
    <buildDir>target</buildDir>
</properties>
<build>
    <directory>${buildDir}</directory>
</build>

and call mvn clean install -DbuildDir=customTargetDir, my project gets built to the customTargetDir as expected.

Why is that? I really don't see a difference. I both cases, I define the value of an existing property.

0 Answers
Related