Relative path to parent directory at multi module maven project

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Relative path to parent directory at multi module maven project

Cem Koc
I have 3 level multi module maven project.  I want to utilize a common plugin configuration at parent pom and the rest of the 2nd and 3rd level modules will utilize this configuration. The plugin configuration has a configuration file for 3rd level modules such as:

<mypluging-config-source-path>../../conf/myplugin</mypluging-config-source-path>

But this configuration could not be used by 2rd level modules. They need

<mypluging-config-source-path>../conf/myplugin</mypluging-config-source-path>

What is the best way to use a common path for all modules in a project even at root parent pom?  
Reply | Threaded
Open this post in threaded view
|

Re: Relative path to parent directory at multi module maven project

Hilco Wijbenga-3
On 19 July 2011 03:01, Cem Koc <[hidden email]> wrote:

> I have 3 level multi module maven project.  I want to utilize a common plugin
> configuration at parent pom and the rest of the 2nd and 3rd level modules
> will utilize this configuration. The plugin configuration has a
> configuration file for 3rd level modules such as:
>
> <mypluging-config-source-path>../../conf/myplugin</mypluging-config-source-path>
>
> But this configuration could not be used by 2rd level modules. They need
>
> <mypluging-config-source-path>../conf/myplugin</mypluging-config-source-path>
>
> What is the best way to use a common path for all modules in a project even
> at root parent pom?

You could set a property with an absolute path in the parent.
Something like <parent-path>${basedir}</parent-path>. Then you can use
that as a starting point:
<myplugin-config-source-path>${parent-path}/conf/myplugin</myplugin-config-source-path>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Relative path to parent directory at multi module maven project

stephenconnolly
On 19 July 2011 16:44, Hilco Wijbenga <[hidden email]> wrote:

> On 19 July 2011 03:01, Cem Koc <[hidden email]> wrote:
> > I have 3 level multi module maven project.  I want to utilize a common
> plugin
> > configuration at parent pom and the rest of the 2nd and 3rd level modules
> > will utilize this configuration. The plugin configuration has a
> > configuration file for 3rd level modules such as:
> >
> >
> <mypluging-config-source-path>../../conf/myplugin</mypluging-config-source-path>
> >
> > But this configuration could not be used by 2rd level modules. They need
> >
> >
> <mypluging-config-source-path>../conf/myplugin</mypluging-config-source-path>
> >
> > What is the best way to use a common path for all modules in a project
> even
> > at root parent pom?
>
> You could set a property with an absolute path in the parent.
> Something like <parent-path>${basedir}</parent-path>. Then you can use
> that as a starting point:
>

Not really as inheritance will kill you by resetting the property in the
child project.


>
> <myplugin-config-source-path>${parent-path}/conf/myplugin</myplugin-config-source-path>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Relative path to parent directory at multi module maven project

Hilco Wijbenga-3
On 19 July 2011 09:16, Stephen Connolly <[hidden email]> wrote:

> On 19 July 2011 16:44, Hilco Wijbenga <[hidden email]> wrote:
>
>> On 19 July 2011 03:01, Cem Koc <[hidden email]> wrote:
>> > I have 3 level multi module maven project.  I want to utilize a common
>> plugin
>> > configuration at parent pom and the rest of the 2nd and 3rd level modules
>> > will utilize this configuration. The plugin configuration has a
>> > configuration file for 3rd level modules such as:
>> >
>> >
>> <mypluging-config-source-path>../../conf/myplugin</mypluging-config-source-path>
>> >
>> > But this configuration could not be used by 2rd level modules. They need
>> >
>> >
>> <mypluging-config-source-path>../conf/myplugin</mypluging-config-source-path>
>> >
>> > What is the best way to use a common path for all modules in a project
>> even
>> > at root parent pom?
>>
>> You could set a property with an absolute path in the parent.
>> Something like <parent-path>${basedir}</parent-path>. Then you can use
>> that as a starting point:
>>
>
> Not really as inheritance will kill you by resetting the property in the
> child project.

Mmmh, yeah, I guess ${basedir} is not a great idea. :-) So either set
*all* properties in the parent (and then simply use them in the
children) or use an environment variable (${env.SHARED_CONF_DIR}).

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Relative path to parent directory at multi module maven project

Marc Rohlfs
I normally define a property called something like
'multiproject.basedir' in every POM - or at least in every POM that
needs to reference a path in the parent project dir.

Some examples:
  - in 'parent/pom.xml' it's:
      <multiproject.basedir>${basedir}<multiproject.basedir>
  - in 'parent/sub1/pom.xml' it's:
      <multiproject.basedir>${basedir}/..<multiproject.basedir>
  - in 'parent/sub1/sub2/pom.xml' it's:
      <multiproject.basedir>${basedir}/../..<multiproject.basedir>

With this, You have a common property to locate Your configuration in
the parent project dir.


Another approach would be similar to Sharing Assembly Descriptors [1].
It's just little more complicated:

1. Create module that contains the all the configuration files. It
should use the Assembly plugin to package the file into a ZIP (or TAR or
whatever) archive and install it to the local repo.

2. Use the dependency:unpack goal to extract the contents of the ZIP
archive, that was created by the new module, and bind it to the
'pre-site' phase. You can do this configuration once in the parent POM
and inherit it to all modules.

2.a. If You like/need, You could use the resources:copy-resources goal
to overwrite the extracted configuration files with custom files that
are placed in the modules. Also bind it to the 'pre-site' phase. This
configuration can also be inherited from the parent to all module POMs.

3. Configure the site plugins to use the unpacked configuration files in
each module. Even this can be done in the parent POM and inherited to
the modules.


Kind regards, Marc


[1]
http://maven.apache.org/plugins/maven-assembly-plugin/examples/sharing-descriptors.html

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Relative path to parent directory at multi module maven project

Cem Koc
In reply to this post by Cem Koc
I was really expecting something very very simple. :) I think that we should file an issue regarding that. What we are trying to do is really very simple and essential. Maybe properties should has another attribute like "final" which is forbidding to be overwritten by children modules? What are your opinions?

Reply | Threaded
Open this post in threaded view
|

Re: Relative path to parent directory at multi module maven project

stephenconnolly
what happens if you have not checked out the parent but only the child
module?

in that case the parent is resolved from the local repo.

You really are pursing an anti-pattern

On 20 July 2011 08:10, Cem Koc <[hidden email]> wrote:

> I was really expecting something very very simple. :) I think that we
> should
> file an issue regarding that. What we are trying to do is really very
> simple
> and essential. Maybe properties should has another attribute like "final"
> which is forbidding to be overwritten by children modules? What are your
> opinions?
>
>
>
> --
> View this message in context:
> http://maven.40175.n5.nabble.com/Relative-path-to-parent-directory-at-multi-module-maven-project-tp4611798p4614958.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Relative path to parent directory at multi module maven project

Cem Koc
@stephenconnolly

Sorry but I could not understand your point exactly. Could you explain a little bid more? You mean because of being at another folder such as my repository it will point somewhere else?

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Relative path to parent directory at multi module maven project

Dennis Lundberg-2
Hi

Referencing a files in another module using relative paths is an
anti-pattern. One reason for this is that it will break your build if
you are using a build server, like Jenkins. The build server will check
out each module into a separate folder, which is not in the same folder
structure that your project is using.

The best practice way of sharing resources like configuration files is
storing them in an archive that is deployed to your repository. When
that is done you can either use it as a dependency, making the resources
available on the class path, or use the dependency:unpack goal to
extract the files to wherever you want them.

On 2011-07-20 13:10, Cem Koc wrote:

> @stephenconnolly
>
> Sorry but I could not understand your point exactly. Could you explain a
> little bid more? You mean because of being at another folder such as my
> repository it will point somewhere else?
>
> Thanks
>
> --
> View this message in context: http://maven.40175.n5.nabble.com/Relative-path-to-parent-directory-at-multi-module-maven-project-tp4611798p4615533.html
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>


--
Dennis Lundberg

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: Relative path to parent directory at multi module maven project

Cem Koc
Thanks for detailed explanation.

In order to not having relative path problems at our build server each modules has it is own script and common workplace.

I will keep in my mind your suggestions. I am strongly agree with your opinion.

Is there any resource for Maven patterns/antipatterns?

Cem
Reply | Threaded
Open this post in threaded view
|

Re: Relative path to parent directory at multi module maven project

xuedm
This post has NOT been accepted by the mailing list yet.
In reply to this post by Cem Koc
Hi Cem,

I found one solution is to leverage pluginManagement in parent pom. The path in pluginManagement should be relative to module.

Thanks,
Dingmeng