In a multi-module maven project, is there a variable that points to the root project folder?
${project.basedir}
points to the current project\'s d
In the latest maven, you can use ${maven.multiModuleProjectDirectory}
.
In Maven 3, ${session.executionRootDirectory}
is "a variable that always points to the ... directory ... from which the maven command was executed."
Note that this is distinct from a property that gives the top-level root directory of a multi-module project, regardless of where in the directory structure mvn
is executed from. Such a property does not exist to my knowledge, but you can use the ${basedir}/..
hack to achieve it. See this thread on maven-users for more details.
See also: Finding the root directory of a multi module maven reactor project
As far I think, there is no such variable. There are only workaround like in accepted answer of Maven2 property that indicates the parent directory .
Such property can be created using: directory-maven-plugin.
Using the plugin's highest-basedir
goal you can assign the root path to any property you specify.
is there a variable that always points to the root directory (the one from which the maven command was executed)
user.dir
(the working directory) should be that directory.
Use directory-maven-plugin with directory-of goal.
Unlike other suggestions:
${session.executionRootDirectory}
The plugin lets you set a property of your choice to the absolute-path of any of the project's modules. In my case I set it to the root module... In my project root pom:
<plugin>
<groupId>org.commonjava.maven.plugins</groupId>
<artifactId>directory-maven-plugin</artifactId>
<version>0.1</version>
<executions>
<execution>
<id>directories</id>
<goals>
<goal>directory-of</goal>
</goals>
<phase>initialize</phase>
<configuration>
<property>myproject.basedir</property>
<project>
<groupId>com.my.domain</groupId>
<artifactId>my-root-artifact</artifactId>
</project>
</configuration>
</execution>
</executions>
</plugin>
From then on, ${myproject.basedir}
in any sub-module pom always has the path of the project root module. And of course, you can set the property to any module, not just the root...