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?

- 11,553
- 8
- 64
- 88

- 3,739
- 8
- 44
- 66
-
1The ambiguity should have never have found its way into the mainstream! – Richard Jessop Aug 12 '21 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.

- 307
- 2
- 12

- 47,113
- 10
- 108
- 118
-
I would suggest an online reference instead of file which is archived into jar. This: http://maven.apache.org/ref/3.0.3/maven-model/maven.html – khmarbaise Nov 13 '12 at 08: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. – maba Nov 13 '12 at 08:59
-
The github mirror allows linking to a specific line number: https://github.com/apache/maven-3/blob/trunk/maven-model-builder/src/main/resources/org/apache/maven/model/pom-4.0.0.xml#L53 Otherwise, it's in svn at: http://svn.apache.org/repos/asf/maven/maven-3/trunk/maven-model-builder/src/main/resources/org/apache/maven/model/pom-4.0.0.xml – Martin Ellis Nov 13 '12 at 10:40
-
@MartinEllis OK, I have updated my answer with a link as well. Thank you! – maba Nov 13 '12 at 10:45
-
I searched the source of the maven repo at https://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: https://github.com/apache/maven/search?p=1&q=%22project.build.directory%22&type=&utf8=%E2%9C%93 – PatS Aug 22 '18 at 16:26
-
False. This is only a subset of project properties from the `POM`. It doesn't include core properties like `project.basedir`, and others. – ingyhere Dec 01 '20 at 17:50
-
Link to doc: https://maven.apache.org/pom.html#the-super-pom which matches https://github.com/apache/maven/blob/master/maven-model-builder/src/main/resources/org/apache/maven/model/pom-4.0.0.xml – SkySpiral7 Aug 17 '23 at 14:23
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.

- 14,080
- 5
- 48
- 107

- 2,350
- 16
- 25
-
1The codehause.org hosting has been terminated and this link does not work any more. – Bartosz Firyn Jun 26 '15 at 09:54
-
Yes, true and sad. I've updated with a working link and quoted the relevant section of the linked page. – sdouglass Jun 26 '15 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. – evaldeslacasa Sep 18 '15 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? – qartal May 09 '18 at 20:31
-
10suppose your project is called project-A, and under project-A, a pom.xml is declared, then `${project.build.sourceDirectory}` points to `project-A/src/main/java`, `${project.build.scriptSourceDirectory}` points to `project-A/src/main/scripts`, `${project.build.testSourceDirectory}` points to `project-A/src/test/java`, `${project.build.directory}` points to `project-A/target`, `${project.build.directory}` points to `project-A/target/classes`, `${project.build.testOutputDirectory}` points to `project-A/target/test-classes`. – sc30 Dec 09 '19 at 17:29
-
-
-
@sc30 Please update the 5th property to, `${project.build.outputDirectory}` points to `project-A/target/classes` – Nishanth Jun 02 '23 at 10:25
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.

- 61
- 1
- 2
-
This doesn't show some of the core properties, like `project.basedir`. In other areas it's incomplete, also. – ingyhere Dec 01 '20 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. – Verhás István Dec 03 '20 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.

- 6,401
- 3
- 29
- 31