In Maven, what does the project.build.directory
refer to? I am a bit confused, does it reference the source code directory or the target directory in the Maven project?
-
1The ambiguity should have never have found its way into the mainstream!– Richard JessopAug 12, 2021 at 18:31
4 Answers
You can find those maven properties in the super pom.
You find the jar here:
${M2_HOME}/lib/maven-model-builder-3.0.3.jar
Open the jar with 7-zip or some other archiver (or use the jar tool).
Navigate to
org/apache/maven/model
There you'll find the pom-4.0.0.xml
.
It contains all those "short cuts":
<project>
...
<build>
<directory>${project.basedir}/target</directory>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
<finalName>${project.artifactId}-${project.version}</finalName>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
<scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/java</testSourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
</testResource>
</testResources>
...
</build>
...
</project>
Update
After some lobbying I am adding a link to the pom-4.0.0.xml
. This allows you to see the properties without opening up the local jar file.
-
I would suggest an online reference instead of file which is archived into jar. This: maven.apache.org/ref/3.0.3/maven-model/maven.html Nov 13, 2012 at 8:38
-
30@khmarbaise Well that's nice as well but it doesn't show you the default value of
project.build.directory
for example. That's what I wanted to show.– mabaNov 13, 2012 at 8:59 -
The github mirror allows linking to a specific line number: github.com/apache/maven-3/blob/trunk/maven-model-builder/src/… Otherwise, it's in svn at: svn.apache.org/repos/asf/maven/maven-3/trunk/… Nov 13, 2012 at 10:40
-
@MartinEllis OK, I have updated my answer with a link as well. Thank you!– mabaNov 13, 2012 at 10:45
-
I searched the source of the maven repo at github.com/apache/maven. A relatively small number of hits (9). Nothing sets that property directly. It's got to be set somewhere! This URL shows the search results I saw: github.com/apache/maven/…– PatSAug 22, 2018 at 16:26
It points to your top level output directory (which by default is target
):
EDIT: As has been pointed out, Codehaus is now sadly defunct. You can find details about these properties from Sonatype here:
If you are ever trying to reference output directories in Maven, you should never use a literal value like target/classes. Instead you should use property references to refer to these directories.
project.build.sourceDirectory project.build.scriptSourceDirectory project.build.testSourceDirectory project.build.outputDirectory project.build.testOutputDirectory project.build.directory
sourceDirectory
,scriptSourceDirectory
, andtestSourceDirectory
provide access to the source directories for the project.outputDirectory
andtestOutputDirectory
provide access to the directories where Maven is going to put bytecode or other build output.directory
refers to the directory which contains all of these output directories.
-
1The codehause.org hosting has been terminated and this link does not work any more. Jun 26, 2015 at 9:54
-
Yes, true and sad. I've updated with a working link and quoted the relevant section of the linked page. Jun 26, 2015 at 23:19
-
8...so
project.base.dir
points to the root directory of the project where the pom.xml is. That's why after that,project.build.directory
defined by Maven is${project.basedir}/target
. Thanks guys, I didn't know this. Sep 18, 2015 at 17:59 -
1Although seems to be true, but how did you get this info: "project.base.dir points to the root directory of the project where the pom.xml is". Where I can see this definition?– qartalMay 9, 2018 at 20:31
-
9suppose your project is called project-A, and under project-A, a pom.xml is declared, then
${project.build.sourceDirectory}
points toproject-A/src/main/java
,${project.build.scriptSourceDirectory}
points toproject-A/src/main/scripts
,${project.build.testSourceDirectory}
points toproject-A/src/test/java
,${project.build.directory}
points toproject-A/target
,${project.build.directory}
points toproject-A/target/classes
,${project.build.testOutputDirectory}
points toproject-A/target/test-classes
.– sc30Dec 9, 2019 at 17:29
You can find the most up to date answer for the value in your project just execute the
mvn3 help:effective-pom
command and find the <build> ... <directory>
tag's value in the result aka in the effective-pom. It will show the value of the Super POM unless you have overwritten.
-
This doesn't show some of the core properties, like
project.basedir
. In other areas it's incomplete, also.– ingyhereDec 1, 2020 at 17:42 -
@ingyhere That is correct, the effective pom does not contain the
project.basedir
. Actually, the reason is that even the super POM doesn't contain. What else do you miss from the effective pom? It sounds interesting to me if you could give some details. Dec 3, 2020 at 10:59
Aside from @Verhás István answer (which I like), I was expecting a one-liner for the question:
${project.reporting.outputDirectory}
resolves to target/site
in your project.