You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Matthew McCullough <ma...@ambientideas.com> on 2007/10/05 21:14:00 UTC

How can I get the path for a root pom.xml's basedir in a multimodule project with pom inheritance

Maven users,

Is there a way to retrieve the super, or super-super pom.xml's ${basedir}
such that it consistently returns the "rootmost pom.xml's path"?  It appears
that ${basedir} is always the leafmost pom's path when running a multimodule
build.

So, for example:
1) I have a pom.xml at the root of my tree.
2) I have pom.xmls in subdirectories that reference the parent
3) I have a property that is defined in the root pom.xml that includes
${basedir}
4) Unfortunately, even when running the build via "mvn install" from the
root, each leaf pom, as it gets invoked, recalculates the
root-pom-defined-property for $(basedir) to be relative to the leaf, not to
the original root.

Any way to get the root pom.xml's path so that I can do a relative pathing
from there?

-Matthew McCullough
Ambient Ideas
-- 
View this message in context: http://www.nabble.com/How-can-I-get-the-path-for-a-root-pom.xml%27s-basedir-in-a-multimodule-project-with-pom-inheritance-tf4577123s177.html#a13065695
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How can I get the path for a root pom.xml's basedir in a multimodule project with pom inheritance

Posted by Jörg Schaible <jo...@gmx.de>.
clamb wrote:

> 
> 
> Jörg Schaible-2 wrote:
>> 
>> Why don't you simply keep those filters in an own module and pack them
>> into
>> an archive? Every other project that needs to access them may declare a
>> dep
>> on that artifact and can user the build-helper plugin to unpack them into
>> a
>> temporary location.
>> 
>> - Jörg
>> 
> 
> Two reasons:
> 
>  1) I'm really new at maven and i still haven't gotten 100% into the maven
> packaging mindset. When i have more time i'll investigate your suggestion
> closer.
> 
>  2) It seems non-intuitive to bundle 4 xml files into an archive, then
> expand that archive out before i compile my java files ('cause i need to
> filter them) for all 12 of my sub-projects vs: have my sub-project simply
> point to the filter in the parent.

Well, if you release your components individually, your solution will simply
not work! The release plugin will checkout the source from the tag into
directory target/checkout and build the component *there*. Obviously your
path no longer matches and the build will break or produce unexpected
results.

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How can I get the path for a root pom.xml's basedir in a multimodule project with pom inheritance

Posted by clamb <cl...@ca.ibm.com>.

Jörg Schaible-2 wrote:
> 
> Why don't you simply keep those filters in an own module and pack them
> into
> an archive? Every other project that needs to access them may declare a
> dep
> on that artifact and can user the build-helper plugin to unpack them into
> a
> temporary location.
> 
> - Jörg
> 

Two reasons:

 1) I'm really new at maven and i still haven't gotten 100% into the maven
packaging mindset. When i have more time i'll investigate your suggestion
closer.

 2) It seems non-intuitive to bundle 4 xml files into an archive, then
expand that archive out before i compile my java files ('cause i need to
filter them) for all 12 of my sub-projects vs: have my sub-project simply
point to the filter in the parent.

-- 
View this message in context: http://www.nabble.com/How-can-I-get-the-path-for-a-root-pom.xml%27s-basedir-in-a-multimodule-project-with-pom-inheritance-tf4577123s177.html#a13435319
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How can I get the path for a root pom.xml's basedir in a multimodule project with pom inheritance

Posted by Jörg Schaible <jo...@gmx.de>.
clamb wrote:

> 
> 
> Matthew McCullough wrote:
>> 
>> This is a creative idea, but appears only to work if your leaf nodes of
>> the project are all at the same level so that the ../../ is consistently
>> just the right amount "back up" the directory tree.
>> 
> 
> Yeah ... that is a limitation. However, once you have each pom.xml setup
> its no longer a problem.
> 
> The following worked for me (maven 2.0.4) as each mvn invocation at a
> particular level has the rootPOM defined according to its own path. I've
> got a project that goes 4 directories deep and am using this in the root
> pom.xml for setting pluginDefaults so i can have my filters for the entire
> project in one directory.
> 
>   <build>
> <pluginManagement>
> <plugins>
> <plugin>
> <inherited>true</inherited>
> ...
> <configuration>
> <defs>${rootPOM}/genericFilters</defs>
> </configuration>
> ...
> </plugin>
> </plugins>
> </pluginManagement>
>   </build>

Why don't you simply keep those filters in an own module and pack them into
an archive? Every other project that needs to access them may declare a dep
on that artifact and can user the build-helper plugin to unpack them into a
temporary location.

- Jörg


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How can I get the path for a root pom.xml's basedir in a multimodule project with pom inheritance

Posted by clamb <cl...@ca.ibm.com>.

Matthew McCullough wrote:
> 
> This is a creative idea, but appears only to work if your leaf nodes of
> the project are all at the same level so that the ../../ is consistently
> just the right amount "back up" the directory tree.
> 

Yeah ... that is a limitation. However, once you have each pom.xml setup its
no longer a problem.

The following worked for me (maven 2.0.4) as each mvn invocation at a
particular level has the rootPOM defined according to its own path. I've got
a project that goes 4 directories deep and am using this in the root pom.xml
for setting pluginDefaults so i can have my filters for the entire project
in one directory. 

  <build>
	<pluginManagement>
		<plugins>
			<plugin>
				<inherited>true</inherited>
				...
				<configuration>
					<defs>${rootPOM}/genericFilters</defs>
				</configuration>
				...
			</plugin>
		</plugins>
	</pluginManagement>
  </build>


-MatthewsProject   <rootPOM>${basedir}</rootPOM>
    +Core                 <rootPOM>${basedir}/../</rootPOM>
        +Server          <rootPOM>${basedir}/../../</rootPOM>
        +Client            <rootPOM>${basedir}/../../</rootPOM>
    +Optional            <rootPOM>${basedir}/../</rootPOM>


-- 
View this message in context: http://www.nabble.com/How-can-I-get-the-path-for-a-root-pom.xml%27s-basedir-in-a-multimodule-project-with-pom-inheritance-tf4577123s177.html#a13434676
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How can I get the path for a root pom.xml's basedir in a multimodule project with pom inheritance

Posted by Matthew McCullough <ma...@ambientideas.com>.
This is a creative idea, but appears only to work if your leaf nodes of the
project are all at the same level so that the ../../ is consistently just
the right amount "back up" the directory tree.

For example, it doesn't appear to work on a project structure like this,
where each node has a pom.xml:

-MatthewsProject
    +Core
        +Server
        +Client
    +Optional

It works for Server and Client, but Core and Optional complain because they
are reaching one level too far out for the parent.

Suggestions?  Is this consistent with what you are seeing as well if you
have a 2 and 3 level deep tree of projects?

Sincerely,
Matthew McCullough
Managing Partner
Ambient Ideas, LLC


clamb wrote:
> 
> OK, i've been fighting this battle for a few days now and have a fairly
> ugly solution.
> 
> in every pom.xml define a common root property:
> 
>   <properties>
>     <rootPOM>${basedir}/../</rootPOM>
>   </properties>
> 
> Ensure that you have enough ../ to reference the rootPOM directory.
> 
> Everywhere you need to refer to this super root directory use ${rootPOM}.
> 
> 
> 
> Matthew McCullough wrote:
>> 
>> My far-from-modern CM group requires that we check in the binary
>> artifacts for our 3ps, and depend on them from a VOB checked out of
>> ClearCase.  So our repo, as is now supported in Maven 2, is a
>> "file://../../3pvob" type of path rather than an HTTP path.
>> 
>> Let me know if you have any more ideas on this.  And thanks again all.
>> 
>> -Matthew
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-can-I-get-the-path-for-a-root-pom.xml%27s-basedir-in-a-multimodule-project-with-pom-inheritance-tf4577123s177.html#a13434309
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How can I get the path for a root pom.xml's basedir in a multimodule project with pom inheritance

Posted by clamb <cl...@ca.ibm.com>.
OK, i've been fighting this battle for a few days now and have a fairly ugly
solution.

in every pom.xml define a common root property:

  <properties>
    <rootPOM>${basedir}/../</rootPOM>
  </properties>

Ensure that you have enough ../ to reference the rootPOM directory.

Everywhere you need to refer to this super root directory use ${rootPOM}.



Matthew McCullough wrote:
> 
> My far-from-modern CM group requires that we check in the binary artifacts
> for our 3ps, and depend on them from a VOB checked out of ClearCase.  So
> our repo, as is now supported in Maven 2, is a "file://../../3pvob" type
> of path rather than an HTTP path.
> 
> Let me know if you have any more ideas on this.  And thanks again all.
> 
> -Matthew
> 

-- 
View this message in context: http://www.nabble.com/How-can-I-get-the-path-for-a-root-pom.xml%27s-basedir-in-a-multimodule-project-with-pom-inheritance-tf4577123s177.html#a13431339
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How can I get the path for a root pom.xml's basedir in a multimodule project with pom inheritance

Posted by Matthew McCullough <ma...@ambientideas.com>.
Philippe,

Excellent comments, and I agree with you on not depending on stuff with
relative paths.  But here's where it gets into a jam.

My far-from-modern CM group requires that we check in the binary artifacts
for our 3ps, and depend on them from a VOB checked out of ClearCase.  So our
repo, as is now supported in Maven 2, is a "file://../../3pvob" type of path
rather than an HTTP path.

So I think with that extra revelation on my part, you can see that I can't
quite "gather these files up" as I would be able to do with a set of
resources, or something similar, but rather actually HAVE to path to the
file-based-repository in this case.  I know this is a tough little problem
here, and it's mostly because of the antiquatedness of my CM group.

Let me know if you have any more ideas on this.  And thanks again all.

-Matthew


Philippe Le Marchand wrote:
> 
> Hi Matthew,
> 
> This question comes back regularly, as I looked for an answer myself...
> I came to the conclusion that, according to some posts on this matter,
> that Maven's philosophy doesn't encourgae the use of relative paths
> connecting modules, as you are never sure that a module will reside on
> the same file system than an other, hence the basic dependency
> mechanism ;-)
> 
> The solution would be to gather all build related resources, like
> filter properties files, in a separate project (jar packaging) and set
> this artifact as a dependency in the modules that need it.
> It should even be declared as an extension, like :
> 
> ...
>   <build>
>     <extensions>
>       <extension>
>         <groupId>my.group.id</groupId>
>         <artifactId>build-tools</artifactId>
>         <version>1.0-SNAPSHOT</version>
>       </extension>
>     </extensions>
> ...
> 
> You therefore just need to access the required resources from the
> classpath.
> A question remains to me : how to do so? :-D
> By declaring my filter like that ?
> 
> ...
>    <filters>
>      <filter>filter-${env}.properties</filter>
>    </filters>
> ...
> 
> The <filter> entry doesn't work, I get :
> 
> [INFO] Error loading property file
> '/path/to/project/folder/filter-myenv.properties'
> 
> I've tried with ${classpath}/filter-${env}.properties,
> ${maven.compile.classpath}/filter-${env}.properties, without
> success...
> 
> Does anybody has an idea?
> 
> Thanks,
> 
> Philippe
> 
> On 10/5/07, Matthew McCullough <ma...@ambientideas.com> wrote:
>>
>> Here's an additional thread on this exact same problem by someone else.
>> Can't find a solution in the thread though:
>>
>> http://mail-archives.apache.org/mod_mbox/maven-continuum-users/200701.mbox/%3C459A99B4.3030107@paycool.net%3E
>>
>>
>>
>> Matthew McCullough wrote:
>> >
>> > Maven users,
>> >
>> > Is there a way to retrieve the super, or super-super pom.xml's
>> ${basedir}
>> > such that it consistently returns the "rootmost pom.xml's path"?  It
>> > appears that ${basedir} is always the leafmost pom's path when running
>> a
>> > multimodule build.
>> >
>> > So, for example:
>> > 1) I have a pom.xml at the root of my tree.
>> > 2) I have pom.xmls in subdirectories that reference the parent
>> > 3) I have a property that is defined in the root pom.xml that includes
>> > ${basedir}
>> > 4) Unfortunately, even when running the build via "mvn install" from
>> the
>> > root, each leaf pom, as it gets invoked, recalculates the
>> > root-pom-defined-property for $(basedir) to be relative to the leaf,
>> not
>> > to the original root.
>> >
>> > Any way to get the root pom.xml's path so that I can do a relative
>> pathing
>> > from there?
>> >
>> > -Matthew McCullough
>> > Ambient Ideas
>> >
>>
>> --
>> View this message in context:
>> http://www.nabble.com/How-can-I-get-the-path-for-a-root-pom.xml%27s-basedir-in-a-multimodule-project-with-pom-inheritance-tf4577123s177.html#a13065923
>> Sent from the Maven - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-can-I-get-the-path-for-a-root-pom.xml%27s-basedir-in-a-multimodule-project-with-pom-inheritance-tf4577123s177.html#a13096572
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How can I get the path for a root pom.xml's basedir in a multimodule project with pom inheritance

Posted by Philippe Le Marchand <pl...@noctis.be>.
Hi Matthew,

This question comes back regularly, as I looked for an answer myself...
I came to the conclusion that, according to some posts on this matter,
that Maven's philosophy doesn't encourgae the use of relative paths
connecting modules, as you are never sure that a module will reside on
the same file system than an other, hence the basic dependency
mechanism ;-)

The solution would be to gather all build related resources, like
filter properties files, in a separate project (jar packaging) and set
this artifact as a dependency in the modules that need it.
It should even be declared as an extension, like :

...
  <build>
    <extensions>
      <extension>
        <groupId>my.group.id</groupId>
        <artifactId>build-tools</artifactId>
        <version>1.0-SNAPSHOT</version>
      </extension>
    </extensions>
...

You therefore just need to access the required resources from the classpath.
A question remains to me : how to do so? :-D
By declaring my filter like that ?

...
   <filters>
     <filter>filter-${env}.properties</filter>
   </filters>
...

The <filter> entry doesn't work, I get :

[INFO] Error loading property file
'/path/to/project/folder/filter-myenv.properties'

I've tried with ${classpath}/filter-${env}.properties,
${maven.compile.classpath}/filter-${env}.properties, without
success...

Does anybody has an idea?

Thanks,

Philippe

On 10/5/07, Matthew McCullough <ma...@ambientideas.com> wrote:
>
> Here's an additional thread on this exact same problem by someone else.
> Can't find a solution in the thread though:
>
> http://mail-archives.apache.org/mod_mbox/maven-continuum-users/200701.mbox/%3C459A99B4.3030107@paycool.net%3E
>
>
>
> Matthew McCullough wrote:
> >
> > Maven users,
> >
> > Is there a way to retrieve the super, or super-super pom.xml's ${basedir}
> > such that it consistently returns the "rootmost pom.xml's path"?  It
> > appears that ${basedir} is always the leafmost pom's path when running a
> > multimodule build.
> >
> > So, for example:
> > 1) I have a pom.xml at the root of my tree.
> > 2) I have pom.xmls in subdirectories that reference the parent
> > 3) I have a property that is defined in the root pom.xml that includes
> > ${basedir}
> > 4) Unfortunately, even when running the build via "mvn install" from the
> > root, each leaf pom, as it gets invoked, recalculates the
> > root-pom-defined-property for $(basedir) to be relative to the leaf, not
> > to the original root.
> >
> > Any way to get the root pom.xml's path so that I can do a relative pathing
> > from there?
> >
> > -Matthew McCullough
> > Ambient Ideas
> >
>
> --
> View this message in context: http://www.nabble.com/How-can-I-get-the-path-for-a-root-pom.xml%27s-basedir-in-a-multimodule-project-with-pom-inheritance-tf4577123s177.html#a13065923
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: How can I get the path for a root pom.xml's basedir in a multimodule project with pom inheritance

Posted by Matthew McCullough <ma...@ambientideas.com>.
Here's an additional thread on this exact same problem by someone else. 
Can't find a solution in the thread though:

http://mail-archives.apache.org/mod_mbox/maven-continuum-users/200701.mbox/%3C459A99B4.3030107@paycool.net%3E



Matthew McCullough wrote:
> 
> Maven users,
> 
> Is there a way to retrieve the super, or super-super pom.xml's ${basedir}
> such that it consistently returns the "rootmost pom.xml's path"?  It
> appears that ${basedir} is always the leafmost pom's path when running a
> multimodule build.
> 
> So, for example:
> 1) I have a pom.xml at the root of my tree.
> 2) I have pom.xmls in subdirectories that reference the parent
> 3) I have a property that is defined in the root pom.xml that includes
> ${basedir}
> 4) Unfortunately, even when running the build via "mvn install" from the
> root, each leaf pom, as it gets invoked, recalculates the
> root-pom-defined-property for $(basedir) to be relative to the leaf, not
> to the original root.
> 
> Any way to get the root pom.xml's path so that I can do a relative pathing
> from there?
> 
> -Matthew McCullough
> Ambient Ideas
> 

-- 
View this message in context: http://www.nabble.com/How-can-I-get-the-path-for-a-root-pom.xml%27s-basedir-in-a-multimodule-project-with-pom-inheritance-tf4577123s177.html#a13065923
Sent from the Maven - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org