Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the super pom basedir in a child module pom?

Tags:

maven-2

maven

I want to define a local repository in my maven project.

I've got a super pom and several child modules. My file structure is :

/root
    /repository
    /child
        pom.xml
    pom.xml

in my super pom I define :

<repository>
    <id>my-local-repo</id>
    <url>file://${basedir}/repository</url>
</repository>

The problem is that in my child pom, the repository defined in my super pom refers to /root/child/repository and so, dependencies cannot be found...

Is there a way to define a path always relative to the super pom ?

If not, what's the best way to solve the problem ?

like image 308
Jerome Cance Avatar asked Jan 02 '12 11:01

Jerome Cance


1 Answers

In this case, at first you could try ${project.parent.basedir}.
As it seems it doesn't work, the simple(and native) way is use complete path (/root/...) or try relative path (../) instead of using ${basedir} variable.

But for me, a great solution would be externalize this configuration into a properties file.
You can use properties-maven-plugin ( http://mojo.codehaus.org/properties-maven-plugin/plugin-info.html ).

With this plugin, properties defined on the properties file can be read just like properties defined inside pom.xml.

From the plugin site:

If you have a properties file called teams.properties with this content:

toronto=raptors
miami=heat

Would be the same as declaring the following in your pom.xml:

<properties> 
  <toronto>raptors</toronto>
  <miami>heat</miami>
</properties>
like image 140
RicardoS Avatar answered Oct 01 '22 02:10

RicardoS