You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Wolf Geldmacher <wo...@abacus.ch> on 2011/04/07 12:45:43 UTC

Inheritance of properties

Hello List.

I'm aiming at introducing maven (mvn 3.0.3 to be precise) in our
company.

In preparation for the task I've set up a company wide POM (c-p-p) and a
project specific POM (c-p-p-p) plus a sample project for the developers
here to use as a template (sample-project) - all included below.

The SCM used is Subversion and the structure of the repositories is
historically grown, which requires me to define a <scm-loc> property
which needs to be reset for every project.

The problem I'm encountering:

After "mvn install" for the company and project wide parent POMs I run
"mvn help:effective-pom" from within the sample-project with unexpected
results:

...
<groupId>com.company</groupId>
<artifactId>sample-project</artifactId>
<version>2012.0.0-SNAPSHOT</version>
<name>A sample project</name>
<description>A very simple example project.</description>
<url>https://doc.company.com/build/trunk/maven/sample-project</url>
<scm>
<connection>scm:svn:https://svn.company.com/repos/build/trunk/maven/sample-project/c-p-p-p/sample-project</connection>    <developerConnection>scm:svn:https://svn.company.com/repos/build/trunk/maven/sample-project/c-p-p-p/sample-project</developerConnection>
<url>scm:svn:https://svn.company.com/repos/build/trunk/maven/sample-project/c-p-p-p/sample-project</url>
</scm>
...

-> The project URL that I explicitly (re-)defined in the
   sample-project's POM is expanded as I would expect.
-> All URLs in the SCM section of the effective POM have a trailing
   "c-p-p-p/sample-project" (as does the project URL if it is inherited
   and not explicitly set it in the sample-project's POM).

I understand that maven does "inheritance before interpolation", so as
the <scm-loc> property is set in the sample-project's POM I would expect
all expansions of the property to have the value defined in the POM.

What am I missing?
Where does the additional suffixing come from?
Is this a bug?
Is there a way to achieve my goal without having to make it explicit in
every single derived POM?

As side remarks: The effective POM fpr c-p-p-p looks ok - no unexpected
tailing traces of the parent POM there; and mvn 2.2.1 behaves exactly
the same way.

Cheers,
Wolf


POMs used

c-p-p/pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <!-- Artifact coordinates -->
  <groupId>com.company</groupId>
  <artifactId>c-p-p</artifactId>
  <version>2012.0.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <!-- Artifact description -->
  <name>Company Parent POM</name>
  <description>Central POM for all of Company.  Defines central
locations, central repositories and central properties.</description>
  <url>https://${doc-host}/${svn-loc}</url>

  <!-- Globally defined properties -->
  <properties>
    <!-- Documentation host -->
    <doc-host>doc.company.com</doc-host>
    <!-- Subversion repository host -->
    <svn-host>svn.company.com</svn-host>
    <!-- readonly access to SVN -->
    <svn-ro>scm:svn:https://${svn-host}/repos</svn-ro>
    <!-- read/write access to SVN -->
    <svn-rw>scm:svn:https://${svn-host}/repos</svn-rw>
    <!-- Current branch in SVN -->
    <svn-branch>trunk</svn-branch>
    <!-- location of artifact in SVN -->
    <svn-loc>build/${svn-branch}/maven/c-p-p</svn-loc>

    <!-- Default encoding used for source files -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <!-- Repositories (SVN integration) -->
  <scm>
    <connection>${svn-ro}/${svn-loc}</connection>
    <developerConnection>${svn-rw}/${svn-loc}</developerConnection>
    <url>${svn-ro}/${svn-loc}</url>
  </scm>

</project>

c-p-p-p/pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <properties>
    <!-- location of artifact in SVN -->
    <svn-loc>build/${svn-branch}/maven</svn-loc>
  </properties>
  
  <!-- Import Company-wide Settings -->
  <parent>
    <groupId>com.company</groupId>
    <artifactId>c-p-p</artifactId>
    <version>2012.0.0-SNAPSHOT</version>
  </parent>

  <!-- This defines generic project settings -->
  <groupId>com.company</groupId>
  <artifactId>c-p-p-p</artifactId>
  <version>2012.0.0-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>Company Project Parent POM</name>
  <description>Central POM for Company Projects. Defines generic project
properties.</description>

</project>

sample-project/pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <!-- Import Company Project Wide Settings -->
  <parent>
    <groupId>com.company</groupId>
    <artifactId>c-p-p-p</artifactId>
    <version>2012.0.0-SNAPSHOT</version>
  </parent>

  <properties>
    <!-- location of artifact in SVN -->
    <svn-loc>build/${svn-branch}/maven/sample-project</svn-loc>
  </properties>

  <!-- Coordinates of the project -->
  <groupId>com.company</groupId>
  <artifactId>sample-project</artifactId>
  <!-- Version inherited from com.company.c-p-p-p!
    <version>2012.0.0-SNAPSHOT</version>
  -->
  <packaging>jar</packaging>
  <name>A sample project</name>
  <description>A very simple example project.</description>
  <!-- The next should *not* be necessary! -->
  <url>https://${doc-host}/${svn-loc}</url>

</project>



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


Re: Inheritance of properties

Posted by Wolf Geldmacher <wo...@abacus.ch>.
Hi Anders,

On Thu, 2011-04-07 at 14:26 +0200, Anders Hammar wrote:
> First of all, I think that you're addressing the (what I call) developer way
> by adding properties for many tings. Even if this would work, it makes the
> poms difficult to read and understand.
What I'm trying to do is to make the *developers' POMs* as easy to read
and understand as possible - a single property that defines the location
of the scm, documentation, a.s.o. is all that would have to be defined.
I don't care as much for the company and project parent POMs as most
developers will never touch or even look at them, if things work out ok
for them.

> I believe future tooling support
> (like m2eclipse) will solve some of this, but I still regard this as the
> developer's approach.
Unfortunately I cannot wait for the tooling support to happen - and yes,
I'm approaching this as a developer who wants to have maximal
(configuration) re-use. I'm trying to swing with the "Convention over
Configuration" approach, but there are some boundaries here that I just
cannot ignore without loosing acceptance for Maven - one of them being
that I cannot disrupt development for reorganizing the structure of the
SCM: A lot of (somewhat brittle) scaffolding has been built around the
SCM structure that I intend to get rid of, but I can only do it
bottom-up, one project & one library at a time, while the whole rest of
the system still behaves and builds as before.

> For example, I would leave the "generic" scm section out of the corporate
> pom. Or more correctly, the corporate pom will have a scm section specifying
> (without the usa of properties) the path to the scm where the corporate pom
> is located. Then for each product, the parent pom would override this by
> declaring the correct scm path for it.
... and the correct site path, and the correct documentation URL, ...
leading to larger POMs and configuration information spreading
throughout all POMs? There must be a better way!

> Have a look at how the corporate pom at Apache, Codehaus, etc is made up.
> Best-practice that works. It will give you some hints of configuration that
> you corp parent do lack.
I did have a look at the ASF POM and I cut out a lot of the stuff that
is in my top-level POM for brevity on the list.

Cheers,
Wolf

>> Cut for brevity.



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


Re: Inheritance of properties

Posted by Anders Hammar <an...@hammar.net>.
First of all, I think that you're addressing the (what I call) developer way
by adding properties for many tings. Even if this would work, it makes the
poms difficult to read and understand. I believe future tooling support
(like m2eclipse) will solve some of this, but I still regard this as the
developer's approach.

For example, I would leave the "generic" scm section out of the corporate
pom. Or more correctly, the corporate pom will have a scm section specifying
(without the usa of properties) the path to the scm where the corporate pom
is located. Then for each product, the parent pom would override this by
declaring the correct scm path for it.

Have a look at how the corporate pom at Apache, Codehaus, etc is made up.
Best-practice that works. It will give you some hints of configuration that
you corp parent do lack.

/Anders

On Thu, Apr 7, 2011 at 12:45, Wolf Geldmacher <wo...@abacus.ch>wrote:

> Hello List.
>
> I'm aiming at introducing maven (mvn 3.0.3 to be precise) in our
> company.
>
> In preparation for the task I've set up a company wide POM (c-p-p) and a
> project specific POM (c-p-p-p) plus a sample project for the developers
> here to use as a template (sample-project) - all included below.
>
> The SCM used is Subversion and the structure of the repositories is
> historically grown, which requires me to define a <scm-loc> property
> which needs to be reset for every project.
>
> The problem I'm encountering:
>
> After "mvn install" for the company and project wide parent POMs I run
> "mvn help:effective-pom" from within the sample-project with unexpected
> results:
>
> ...
> <groupId>com.company</groupId>
> <artifactId>sample-project</artifactId>
> <version>2012.0.0-SNAPSHOT</version>
> <name>A sample project</name>
> <description>A very simple example project.</description>
> <url>https://doc.company.com/build/trunk/maven/sample-project</url>
> <scm>
> <connection>scm:svn:
> https://svn.company.com/repos/build/trunk/maven/sample-project/c-p-p-p/sample-project</connection>
>    <developerConnection>scm:svn:
> https://svn.company.com/repos/build/trunk/maven/sample-project/c-p-p-p/sample-project
> </developerConnection>
> <url>scm:svn:
> https://svn.company.com/repos/build/trunk/maven/sample-project/c-p-p-p/sample-project
> </url>
> </scm>
> ...
>
> -> The project URL that I explicitly (re-)defined in the
>   sample-project's POM is expanded as I would expect.
> -> All URLs in the SCM section of the effective POM have a trailing
>   "c-p-p-p/sample-project" (as does the project URL if it is inherited
>   and not explicitly set it in the sample-project's POM).
>
> I understand that maven does "inheritance before interpolation", so as
> the <scm-loc> property is set in the sample-project's POM I would expect
> all expansions of the property to have the value defined in the POM.
>
> What am I missing?
> Where does the additional suffixing come from?
> Is this a bug?
> Is there a way to achieve my goal without having to make it explicit in
> every single derived POM?
>
> As side remarks: The effective POM fpr c-p-p-p looks ok - no unexpected
> tailing traces of the parent POM there; and mvn 2.2.1 behaves exactly
> the same way.
>
> Cheers,
> Wolf
>
>
> POMs used
>
> c-p-p/pom.xml:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0"
>         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/maven-v4_0_0.xsd">
>  <modelVersion>4.0.0</modelVersion>
>
>  <!-- Artifact coordinates -->
>  <groupId>com.company</groupId>
>  <artifactId>c-p-p</artifactId>
>  <version>2012.0.0-SNAPSHOT</version>
>  <packaging>pom</packaging>
>
>  <!-- Artifact description -->
>  <name>Company Parent POM</name>
>  <description>Central POM for all of Company.  Defines central
> locations, central repositories and central properties.</description>
>  <url>https://${doc-host}/${svn-loc}</url>
>
>  <!-- Globally defined properties -->
>  <properties>
>    <!-- Documentation host -->
>    <doc-host>doc.company.com</doc-host>
>    <!-- Subversion repository host -->
>    <svn-host>svn.company.com</svn-host>
>    <!-- readonly access to SVN -->
>    <svn-ro>scm:svn:https://${svn-host}/repos</svn-ro>
>    <!-- read/write access to SVN -->
>    <svn-rw>scm:svn:https://${svn-host}/repos</svn-rw>
>    <!-- Current branch in SVN -->
>    <svn-branch>trunk</svn-branch>
>    <!-- location of artifact in SVN -->
>    <svn-loc>build/${svn-branch}/maven/c-p-p</svn-loc>
>
>    <!-- Default encoding used for source files -->
>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
>  </properties>
>
>  <!-- Repositories (SVN integration) -->
>  <scm>
>    <connection>${svn-ro}/${svn-loc}</connection>
>    <developerConnection>${svn-rw}/${svn-loc}</developerConnection>
>    <url>${svn-ro}/${svn-loc}</url>
>  </scm>
>
> </project>
>
> c-p-p-p/pom.xml:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd">
>  <modelVersion>4.0.0</modelVersion>
>
>  <properties>
>    <!-- location of artifact in SVN -->
>    <svn-loc>build/${svn-branch}/maven</svn-loc>
>  </properties>
>
>  <!-- Import Company-wide Settings -->
>  <parent>
>    <groupId>com.company</groupId>
>    <artifactId>c-p-p</artifactId>
>    <version>2012.0.0-SNAPSHOT</version>
>  </parent>
>
>  <!-- This defines generic project settings -->
>  <groupId>com.company</groupId>
>  <artifactId>c-p-p-p</artifactId>
>  <version>2012.0.0-SNAPSHOT</version>
>  <packaging>pom</packaging>
>  <name>Company Project Parent POM</name>
>  <description>Central POM for Company Projects. Defines generic project
> properties.</description>
>
> </project>
>
> sample-project/pom.xml:
>
> <project xmlns="http://maven.apache.org/POM/4.0.0"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd">
>  <modelVersion>4.0.0</modelVersion>
>
>  <!-- Import Company Project Wide Settings -->
>  <parent>
>    <groupId>com.company</groupId>
>    <artifactId>c-p-p-p</artifactId>
>    <version>2012.0.0-SNAPSHOT</version>
>  </parent>
>
>  <properties>
>    <!-- location of artifact in SVN -->
>    <svn-loc>build/${svn-branch}/maven/sample-project</svn-loc>
>  </properties>
>
>  <!-- Coordinates of the project -->
>  <groupId>com.company</groupId>
>  <artifactId>sample-project</artifactId>
>  <!-- Version inherited from com.company.c-p-p-p!
>    <version>2012.0.0-SNAPSHOT</version>
>  -->
>  <packaging>jar</packaging>
>  <name>A sample project</name>
>  <description>A very simple example project.</description>
>  <!-- The next should *not* be necessary! -->
>  <url>https://${doc-host}/${svn-loc}</url>
>
> </project>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Inheritance of properties

Posted by Jörg Schaible <jo...@gmx.de>.
Hi Wolf,

Wolf Geldmacher wrote:

> Hi Jörg,
> 
> Thanks for the answer.
> 
> Can you point me to a place where this behaviour is documented?
> 
> It seems to hold for most, but not all URLs, i.e. scm, project URL and
> documentation site URL (except for the webAccessUrl of the
> maven-project-info-reports-plugin which remains untouched!) seem to be
> affected, repository URLs seem to be not affected.
> 
> ... and it's not always the current artifactId either - frequently it's
> the parent-POMs artifactId followed by the current artifactId, but again
> this does not seem to be the case always.

I don't know where it is actually documented, but it has a looong history 
http://jira.codehaus.org/browse/MNG-3244 (and linked issues)

- Jörg



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


Re: Inheritance of properties

Posted by Wolf Geldmacher <wo...@abacus.ch>.
Hi Jörg,

Thanks for the answer.

Can you point me to a place where this behaviour is documented?

It seems to hold for most, but not all URLs, i.e. scm, project URL and
documentation site URL (except for the webAccessUrl of the
maven-project-info-reports-plugin which remains untouched!) seem to be
affected, repository URLs seem to be not affected.

... and it's not always the current artifactId either - frequently it's
the parent-POMs artifactId followed by the current artifactId, but again
this does not seem to be the case always.

Thanks again,
Wolf


On Thu, 2011-04-07 at 14:35 +0200, Jörg Schaible wrote: 
> Hi Wolf,
> 
> Wolf Geldmacher wrote:
> 
> > Hello List.
> > 
> > I'm aiming at introducing maven (mvn 3.0.3 to be precise) in our
> > company.
> > 
> > In preparation for the task I've set up a company wide POM (c-p-p) and a
> > project specific POM (c-p-p-p) plus a sample project for the developers
> > here to use as a template (sample-project) - all included below.
> > 
> > The SCM used is Subversion and the structure of the repositories is
> > historically grown, which requires me to define a <scm-loc> property
> > which needs to be reset for every project.
> > 
> > The problem I'm encountering:
> > 
> > After "mvn install" for the company and project wide parent POMs I run
> > "mvn help:effective-pom" from within the sample-project with unexpected
> > results:
> > 
> > ...
> > <groupId>com.company</groupId>
> > <artifactId>sample-project</artifactId>
> > <version>2012.0.0-SNAPSHOT</version>
> > <name>A sample project</name>
> > <description>A very simple example project.</description>
> > <url>https://doc.company.com/build/trunk/maven/sample-project</url>
> > <scm>
> > 
> <connection>scm:svn:https://svn.company.com/repos/build/trunk/maven/sample-
> project/c-p-p-p/sample-project</connection>
> >   
> > 
> <developerConnection>scm:svn:https://svn.company.com/repos/build/trunk/maven/sample-
> project/c-p-p-p/sample-project</developerConnection>
> > <url>scm:svn:https://svn.company.com/repos/build/trunk/maven/sample-
> project/c-p-p-p/sample-project</url>
> > </scm> ...
> > 
> > -> The project URL that I explicitly (re-)defined in the
> >    sample-project's POM is expanded as I would expect.
> > -> All URLs in the SCM section of the effective POM have a trailing
> >    "c-p-p-p/sample-project" (as does the project URL if it is inherited
> >    and not explicitly set it in the sample-project's POM).
> > 
> > I understand that maven does "inheritance before interpolation", so as
> > the <scm-loc> property is set in the sample-project's POM I would expect
> > all expansions of the property to have the value defined in the POM.
> > 
> > What am I missing?
> > Where does the additional suffixing come from?
> 
> The artifactId is automatically appended as suffix when URLs are inherited.
> 
> > Is this a bug?
> 
> No.
> 
> > Is there a way to achieve my goal without having to make it explicit in
> > every single derived POM?
> 
> No.
> 
> > As side remarks: The effective POM fpr c-p-p-p looks ok - no unexpected
> > tailing traces of the parent POM there; and mvn 2.2.1 behaves exactly
> > the same way.
> 
> BTW: The behavior *is* annoying. It's not only that it prevents 
> interpolation, it also silently implies that the artifactId matches the 
> folder structure in the SCM.
> 
> - Jörg
> 
> 
> ---------------------------------------------------------------------
> 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: Inheritance of properties

Posted by Jörg Schaible <jo...@scalaris.com>.
Hi Wolf,

Wolf Geldmacher wrote:

> Hello List.
> 
> I'm aiming at introducing maven (mvn 3.0.3 to be precise) in our
> company.
> 
> In preparation for the task I've set up a company wide POM (c-p-p) and a
> project specific POM (c-p-p-p) plus a sample project for the developers
> here to use as a template (sample-project) - all included below.
> 
> The SCM used is Subversion and the structure of the repositories is
> historically grown, which requires me to define a <scm-loc> property
> which needs to be reset for every project.
> 
> The problem I'm encountering:
> 
> After "mvn install" for the company and project wide parent POMs I run
> "mvn help:effective-pom" from within the sample-project with unexpected
> results:
> 
> ...
> <groupId>com.company</groupId>
> <artifactId>sample-project</artifactId>
> <version>2012.0.0-SNAPSHOT</version>
> <name>A sample project</name>
> <description>A very simple example project.</description>
> <url>https://doc.company.com/build/trunk/maven/sample-project</url>
> <scm>
> 
<connection>scm:svn:https://svn.company.com/repos/build/trunk/maven/sample-
project/c-p-p-p/sample-project</connection>
>   
> 
<developerConnection>scm:svn:https://svn.company.com/repos/build/trunk/maven/sample-
project/c-p-p-p/sample-project</developerConnection>
> <url>scm:svn:https://svn.company.com/repos/build/trunk/maven/sample-
project/c-p-p-p/sample-project</url>
> </scm> ...
> 
> -> The project URL that I explicitly (re-)defined in the
>    sample-project's POM is expanded as I would expect.
> -> All URLs in the SCM section of the effective POM have a trailing
>    "c-p-p-p/sample-project" (as does the project URL if it is inherited
>    and not explicitly set it in the sample-project's POM).
> 
> I understand that maven does "inheritance before interpolation", so as
> the <scm-loc> property is set in the sample-project's POM I would expect
> all expansions of the property to have the value defined in the POM.
> 
> What am I missing?
> Where does the additional suffixing come from?

The artifactId is automatically appended as suffix when URLs are inherited.

> Is this a bug?

No.

> Is there a way to achieve my goal without having to make it explicit in
> every single derived POM?

No.

> As side remarks: The effective POM fpr c-p-p-p looks ok - no unexpected
> tailing traces of the parent POM there; and mvn 2.2.1 behaves exactly
> the same way.

BTW: The behavior *is* annoying. It's not only that it prevents 
interpolation, it also silently implies that the artifactId matches the 
folder structure in the SCM.

- Jörg


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