Reputation: 2531
Is there way to get parent directory for ${basedir}
in my pom.xml? Currently I have
<earSourceDirectory>${basedir}/EAR/src/main/resources</earSourceDirectory>
but I need to access parent directory of basedir as my resources lies in different maven project.
How can I get the parent folder of ${basedir}
?
Upvotes: 19
Views: 45192
Reputation: 136
I had the requirement of moving zip generated in MainDirectory/Submodule/target/ to MainDirectory/target/. I tried all solutions from everywhere but I was unable to solve. I finally tried Ant plugin in pom.xml of submodule to copy as below:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>copy to parent target</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<copy todir="../target/" overwrite="true" flatten="true">
<fileset dir="${basedir}/target/"/>
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>
Upvotes: 1
Reputation: 14697
In the children:
<properties>
<main.basedir>${project.parent.basedir}</main.basedir>
</properties>
In the grandchildren:
<properties>
<main.basedir>${project.parent.parent.basedir}</main.basedir>
</properties>
Upvotes: 13
Reputation: 12335
Please, don't try to go outside the basedir, because it's considered a very bad practice.
Even if you succeed now, it will be the start of a workaround over workaround, trying to battle Maven. In the end, Maven will win.
If a developer checks out a directory with a pom.xml
, it should be able run the project with mvn verify
without any references to other directories.
If these are shared resources, make it a separate project and include it as a dependency (search for multi module projects). Or use the maven-remote-resources-plugin to pull these resources into your project.
Upvotes: 7
Reputation: 3657
${project.basedir}/../
However, access resources in a different module is something I try to avoid. I'd suggest using the unpack goal of the maven-dependency-plugin.
Upvotes: 14