You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Florian Schätz <FS...@assona.net> on 2016/12/02 11:31:31 UTC

${project.parent.parent.version} does not work

Hello,

for a project I would like to resolve the "grandparent" version:

<grandparent.version>${project.parent.parent.version}</grandparent.version>

Unfortunately, with Maven 3.3.9 this simply doesn't work, the effective
pom shows it as unresolved:

<grandparent.version>${project.parent.parent.version}</grandparent.version>

I can reproduce it with any new probject a simple way is, for example,
using a spring boot project (which should have a parent
(spring-boot-parent) and a grandparent (spring-boot-dependencies):

<?xml version="1.0" encoding="UTF-8"?>
<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>

	<groupId>com.example</groupId>
	<artifactId>demo</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.4.2.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>

<grandparent.version>${project.parent.parent.version}</grandparent.version>
	</properties>	
	
</project>

Any ideas how to access the parent.parent.version otherwise?
Unfortunately, I only found closed issues where
${project.parent.parent.version} was given as a workaround...


Re: ${project.parent.parent.version} does not work

Posted by Christian Schulte <cs...@schulte.it>.
Am 12/05/16 um 21:51 schrieb Florian Sch�tz:
> Hello,
> 
> On 05/12/2016 21:37, Christian Schulte wrote:
> 
>> Only way to get at that would be to declare a property in that
>> grandparent's POM. The parent/child hierarchies really are used in the
>> opposite way. You inherit versions from parents, for example (top-down,
>> so to say). What use-case is it requiring access to a grandparent's
>> version (bottom-up)?
> 
> Ok, basically, I have three projects:
> 
> shared-core
>   +some modules
> application1
>   +some modules
> application2
>   +some modules
> 
> application1 and application2 both use the shared-core project's modules 
> as dependencies, the application's top level project is just a pom (for 
> more specific dependency management). During each development cycle 
> (sprint), the shared-core will also be worked on and at the end, 
> released (with a different version than the application itself). So, 
> what we did is putting the parent pom (for dependency management) into 
> the shared-core, giving us this parent pom hierarchy...
> 
> shared-core pom.xml (pom)
>   - shared-core module1 pom.xml (jar)
>   - shared-core module2 pom.xml (jar)
>   - application1 parent pom.xml (pom)
>     - application 1 module 1 pom.xml (jar)
>     - application 1 module 2 pom.xml (jar)
>   - application2 parent pom.xml (pom)
>     - application 2 module 1 pom.xml (jar)
>     - application 2 module 2 pom.xml (jar)
> etc.
> 

I would split this into three standalone multi-module projects. The
"shared" multi-module project, the "app1" multi-module project and the
"app2" multi-module project. In the "app1" and "app2" POMs I would use a
property for the version to use of "shared" and maybe I would make the
"shared" multi-module project provide a POM packaging project providing
dependency management information to be imported in "app1" or "app2"
using the "import" scope feature. I would use SNAPSHOTs during
development so that you do not need to update "app1" or "app2" POMs
whenever something in "shared" changes. I would then use the release
plugin whenever I would want to release "app1" or "app2" and that would
notice that SNAPSHOT versions are in use and would ask for the release
version to use. That may lead to releasing "shared" before. Once "app1"
or "app2" have been set to release versions of "shared", you will not
update that to a SNAPSHOT when the changes in  "shared" are not needed
in "app1" or "app2" sooner or later. Will you really ever release "app1"
and "app2" in one go once you've performed some initial releases? How
would you handle bugfix/hotfix releases? All of this just to not "mvn
install" shared when something has changed independently of "app1" or
"app2"?


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


Re: ${project.parent.parent.version} does not work

Posted by Christian Schulte <cs...@schulte.it>.
Am 12/05/16 um 21:51 schrieb Florian Sch�tz:
> shared-core pom.xml (pom)
>   - shared-core module1 pom.xml (jar)
>   - shared-core module2 pom.xml (jar)
>   - application1 parent pom.xml (pom)
>     - application 1 module 1 pom.xml (jar)
>     - application 1 module 2 pom.xml (jar)
>   - application2 parent pom.xml (pom)
>     - application 2 module 1 pom.xml (jar)
>     - application 2 module 2 pom.xml (jar)
> etc.

Looking at this there are at least two roles involved. There is the
"shared" role. Let's call that the "framework developer" role. Then
there is the "application" role. Let's call that the "application
developer" role. For you, it happens that these two roles are realized
by the same individuals. These are the questions you need to answer
yourself:

Who is responsible for "shared"? What "role" is managing the way it will
evolve? Is it ok that each and every developer can change "shared"
without any kind of coordination? Everyone can do anything without any
need to communicate solutions or requirements here? Really nothing to
manage here?

Who is responsible for "app1" or "app2"? What "role" is managing the way
these will evolve? Is it ok that each and every developer can change
"app1" or "app2" without any kind of coordination? Everyone can do
anything without any need to communicate solutions or requirements here?
Really nothing to manage here?


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


Re: ${project.parent.parent.version} does not work

Posted by Florian Schätz <ma...@florian-schaetz.de>.
Hello,

On 05/12/2016 21:37, Christian Schulte wrote:

> Only way to get at that would be to declare a property in that
> grandparent's POM. The parent/child hierarchies really are used in the
> opposite way. You inherit versions from parents, for example (top-down,
> so to say). What use-case is it requiring access to a grandparent's
> version (bottom-up)?

Ok, basically, I have three projects:

shared-core
  +some modules
application1
  +some modules
application2
  +some modules

application1 and application2 both use the shared-core project's modules 
as dependencies, the application's top level project is just a pom (for 
more specific dependency management). During each development cycle 
(sprint), the shared-core will also be worked on and at the end, 
released (with a different version than the application itself). So, 
what we did is putting the parent pom (for dependency management) into 
the shared-core, giving us this parent pom hierarchy...

shared-core pom.xml (pom)
  - shared-core module1 pom.xml (jar)
  - shared-core module2 pom.xml (jar)
  - application1 parent pom.xml (pom)
    - application 1 module 1 pom.xml (jar)
    - application 1 module 2 pom.xml (jar)
  - application2 parent pom.xml (pom)
    - application 2 module 1 pom.xml (jar)
    - application 2 module 2 pom.xml (jar)
etc.

All the modules of shared-core have the same version, as have the 
modules of application1 and application2 (but not the same as the other 
application, obviously).

What I want is to manage the dependencies in the shared-core pom.xml, 
for example:

<depencencyManagement>
   <dependencies>
     <dependency>
         <group>com.example</group>
         <artifactId>shared-core-module-1</artifactId>
         <version>${project.version}</version>
     </dependency>
   </dependencies>
</depencencyManagement>

But that's now the problem, INSIDE shared-core, the version number is 
correct, but inside any of application1 modules, it's not, since then it 
tries to use application1's version number which doesn't have anything 
to do with shard-core's.

So, what I would need inside application 1 module 1, would be the 
grandparent version (version = application 1 module 1 version, parent 
version = application 1 version, grandparent version = shared-core version).

So, as a workaround, when building, I would set the version number of 
shared-parent (thus updating the versions of the modules) and update a 
setting which duplicates this version for the dependency management. 
Unfortunately, versions:update-property makes it quite hard to actually 
do so and I start thinking that a simple shell command to regex replace 
inside the pom would be quicker...

Flo

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


Re: ${project.parent.parent.version} does not work

Posted by Christian Schulte <cs...@schulte.it>.
Am 12/05/16 um 20:33 schrieb Florian Sch�tz:
> <version>${project.parent.version}</version> directly instead? But 
> unfortunately, I don't need the parent version, but the grand parent 
> version and I don't see a way to get it this way...

Only way to get at that would be to declare a property in that
grandparent's POM. The parent/child hierarchies really are used in the
opposite way. You inherit versions from parents, for example (top-down,
so to say). What use-case is it requiring access to a grandparent's
version (bottom-up)?


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


Re: ${project.parent.parent.version} does not work

Posted by Florian Schätz <ma...@florian-schaetz.de>.
On 05/12/2016 15:09, Robert Patrick wrote:

 > If you don\u2019t want to compute the value dynamically, The simplest way 
 > to set a property is using -Dgrandparent.version=1.2.3 on the
 > command-line (or in the project's .mvn/maven.config file).

Not something I want to do, since I want to have all the correct version 
numbers, etc. in my git repository at the right tags, etc. and using a 
dynamic property would prevent that, since only at maven-runtime, the 
property would be filled and in git, it would be whatever default it has.

So, my build should run the version:set, update the numbers, 
commit&push, create the correct tag, etc. This wouldn't work when I just 
set the property during runtime without writing it back in the pom.

 > Another way that you might solve the problem is simply by chaining
 > properties.
 > In any one of the parent hierarchy POMs, set
 > <grandparent.version>...</grandparent.version>
 > and then in the module POM, just say
 > <version>${grandparent.version}</version>.

Sorry, I don't get this.

 > For example, if you put this in the parent POM, just set
 > <grandparent.version>${project.parent.version}</grandparent.version>.

...yes? Wouldn't that be the same as using 
<version>${project.parent.version}</version> directly instead? But 
unfortunately, I don't need the parent version, but the grand parent 
version and I don't see a way to get it this way...

Regards,

Flo

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


Re: ${project.parent.parent.version} does not work

Posted by Christian Schulte <cs...@schulte.it>.
Am 05.12.2016 um 15:09 schrieb Robert Patrick:
> Right, it looks at versions to try to find the latest version number.  
> 
> Another way that you might solve the problem is simply by chaining properties.  In any one of the parent hierarchy POMs, set <grandparent.version>...</grandparent.version> and then in the module POM, just say <version>${grandparent.version}</version>.  

This will likely produce a warning like "version must be a constant".
Why not simply inherit the version from the parent? What exactly do you
need the grandparent's version for? If this is needed in child POMs, the
author of the grandparent should provide a way to inherit that information.


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


RE: ${project.parent.parent.version} does not work

Posted by Robert Patrick <ro...@oracle.com>.
Right, it looks at versions to try to find the latest version number.  

If you don’t want to compute the value dynamically, The simplest way to set a property is using -Dgrandparent.version=1.2.3 on the command-line (or in the project's .mvn/maven.config file).  Another way that you might solve the problem is simply by chaining properties.  In any one of the parent hierarchy POMs, set <grandparent.version>...</grandparent.version> and then in the module POM, just say <version>${grandparent.version}</version>.  For example, if you put this in the parent POM, just set <grandparent.version>${project.parent.version}</grandparent.version>.



-----Original Message-----
From: Florian Schätz [mailto:FSchaetz@assona.net] 
Sent: Monday, December 05, 2016 7:51 AM
To: users@maven.apache.org
Subject: Re: ${project.parent.parent.version} does not work

Am Sonntag, den 04.12.2016, 14:56 -0600 schrieb Robert Patrick:

> versions:update-property seems like a good choice.

Unfortunately, the important word is "seems". versions:update-property does some complicated stuff, I have not yet found a way to simply use it to set property X to value Y. It does some strange range stuff, etc.

> Sent from my iDevice
> 
> > On Dec 4, 2016, at 8:22 AM, Florian Schätz <ma...@florian-schaetz.de> wrote:
> > 
> > Hello,
> > 
> >> For now, you can make that property a constant in the grandparent 
> >> like "<grandparent.version>1.0.0-SNAPSHOT</grandparent.version>" 
> >> and use that property itself in the grandparent like 
> >> "<version>${grandparent.version}</version>". Should not override 
> >> that property in modules, of course.
> > 
> > But that would require me to always update that property somehow whenever I call versions:set, too. Will have to search for an easy way to do so. Any suggestions?
> > 
> > Regards,
> > 
> > Florian
> > 
> > --------------------------------------------------------------------
> > - 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
> 


---------------------------------------------------------------------
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: ${project.parent.parent.version} does not work

Posted by Florian Schätz <FS...@assona.net>.
Am Sonntag, den 04.12.2016, 14:56 -0600 schrieb Robert Patrick:

> versions:update-property seems like a good choice.

Unfortunately, the important word is "seems". versions:update-property
does some complicated stuff, I have not yet found a way to simply use it
to set property X to value Y. It does some strange range stuff, etc.

> Sent from my iDevice
> 
> > On Dec 4, 2016, at 8:22 AM, Florian Schätz <ma...@florian-schaetz.de> wrote:
> > 
> > Hello,
> > 
> >> For now, you can make that property a constant in the grandparent like
> >> "<grandparent.version>1.0.0-SNAPSHOT</grandparent.version>" and use that
> >> property itself in the grandparent like
> >> "<version>${grandparent.version}</version>". Should not override that
> >> property in modules, of course.
> > 
> > But that would require me to always update that property somehow whenever I call versions:set, too. Will have to search for an easy way to do so. Any suggestions?
> > 
> > Regards,
> > 
> > Florian
> > 
> > ---------------------------------------------------------------------
> > 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
> 


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

Re: ${project.parent.parent.version} does not work

Posted by Robert Patrick <ro...@oracle.com>.
versions:update-property seems like a good choice.


Sent from my iDevice

> On Dec 4, 2016, at 8:22 AM, Florian Schätz <ma...@florian-schaetz.de> wrote:
> 
> Hello,
> 
>> For now, you can make that property a constant in the grandparent like
>> "<grandparent.version>1.0.0-SNAPSHOT</grandparent.version>" and use that
>> property itself in the grandparent like
>> "<version>${grandparent.version}</version>". Should not override that
>> property in modules, of course.
> 
> But that would require me to always update that property somehow whenever I call versions:set, too. Will have to search for an easy way to do so. Any suggestions?
> 
> Regards,
> 
> Florian
> 
> ---------------------------------------------------------------------
> 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: ${project.parent.parent.version} does not work

Posted by Florian Schätz <ma...@florian-schaetz.de>.
Hello,

> For now, you can make that property a constant in the grandparent like
> "<grandparent.version>1.0.0-SNAPSHOT</grandparent.version>" and use that
> property itself in the grandparent like
> "<version>${grandparent.version}</version>". Should not override that
> property in modules, of course.

But that would require me to always update that property somehow 
whenever I call versions:set, too. Will have to search for an easy way 
to do so. Any suggestions?

Regards,

Florian

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


Re: ${project.parent.parent.version} does not work

Posted by Christian Schulte <cs...@schulte.it>.
Am 12/02/16 um 21:14 schrieb Florian Sch�tz:
> And this I can't see a way to store the grandparent version in a 
> property via a ${project.version}, because every child will override it 

<https://issues.apache.org/jira/browse/MNG-5900>

For now, you can make that property a constant in the grandparent like
"<grandparent.version>1.0.0-SNAPSHOT</grandparent.version>" and use that
property itself in the grandparent like
"<version>${grandparent.version}</version>". Should not override that
property in modules, of course.

Regards,
-- 
Christian


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


Re: ${project.parent.parent.version} does not work

Posted by Florian Schätz <ma...@florian-schaetz.de>.
>> Is there any other chance to get the grandparent version - preferably
>> without writing another maven plugin ;-)
>
> If you control the grandparent POM, you can put a property there and set it
> to ${project.version} and then it should be inherited in the descendants.

Erm... Not really? That's why I need the whole thing...

Let's assume I have a parent project, let's call it "example-parent" 
with version "0.0.1-SNAPSHOT". There I set a property...

<properties>
    <example.parent.version>${project.version}</example.parent.version>
</properties>

No surprise there, the effective pom shows me that example-parent has 
the property example.parent.version=0.0.1-SNAPSHOT

Then I make a new project, let's call it "example-child" which has 
"example-parent" as a parent. Let's give example-child now version 
0.0.2-SNAPSHOT and the effective pom of example-child shows us...

<properties>
    <example.parent.version>0.0.2-SNAPSHOT</example.parent.version>
</properties>

...because the ${project.version} now is resolved by calling the 
example-child's version. And the information that was stored in the 
property is effectively overwritten.

And this I can't see a way to store the grandparent version in a 
property via a ${project.version}, because every child will override it 
and put it's own version there. So every child and grandchild will 
effectively only get it's own ${project.version} and not the 
project.version of the grandparent.

> If you don't control the grandparent, then sorry, I don't know a simple
> way. Although you could elaborate on why you need this, and perhaps there
> is a different/better/simpler approach.

I do control it, but as you see above, the information cannot be stored 
that way. I only could duplicate it, but this would make using 
versions:set overly complicated, but that would have to put the version 
into the property, too.

Regards,

Flo

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


Re: ${project.parent.parent.version} does not work

Posted by Curtis Rueden <ct...@wisc.edu>.
Hi Flo,

> Is there any other chance to get the grandparent version - preferably
> without writing another maven plugin ;-)

If you control the grandparent POM, you can put a property there and set it
to ${project.version} and then it should be inherited in the descendants.

If you don't control the grandparent, then sorry, I don't know a simple
way. Although you could elaborate on why you need this, and perhaps there
is a different/better/simpler approach.

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - http://loci.wisc.edu/software


On Fri, Dec 2, 2016 at 12:30 PM, Florian Schätz <ma...@florian-schaetz.de>
wrote:

> Hello,
>
> Was it expected to work with Maven 2, before the whole effective pom
>> calculation was rewritten?
>> Did you try?
>>
>
> No, don't have Maven 2 here, it was just referenced as a workaround in
>
> https://issues.apache.org/jira/browse/MASSEMBLY-367
>
> and in a comment in...
>
> http://stackoverflow.com/questions/6948091/maven-retrieving-
> the-main-module-version-from-a-sub-module
>
> Is there any other chance to get the grandparent version - preferably
> without writing another maven plugin ;-)
>
> Regards,
>
> Flo
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: ${project.parent.parent.version} does not work

Posted by Florian Schätz <ma...@florian-schaetz.de>.
Hello,

> Was it expected to work with Maven 2, before the whole effective pom
> calculation was rewritten?
> Did you try?

No, don't have Maven 2 here, it was just referenced as a workaround in

https://issues.apache.org/jira/browse/MASSEMBLY-367

and in a comment in...

http://stackoverflow.com/questions/6948091/maven-retrieving-the-main-module-version-from-a-sub-module

Is there any other chance to get the grandparent version - preferably 
without writing another maven plugin ;-)

Regards,

Flo

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


Re: ${project.parent.parent.version} does not work

Posted by Hervé BOUTEMY <he...@free.fr>.
I confirm that it is not expected to work currently: here is the reference 
documentation for pom interpolation:
http://maven.apache.org/ref/3-LATEST/maven-model-builder/
index.html#Model_Interpolation

there is not parent element in parent

Was it expected to work with Maven 2, before the whole effective pom 
calculation was rewritten?
Did you try?

Regards,

Hervé

Le vendredi 2 décembre 2016, 11:31:31 CET Florian Schätz a écrit :
> Hello,
> 
> for a project I would like to resolve the "grandparent" version:
> 
> <grandparent.version>${project.parent.parent.version}</grandparent.version>
> 
> Unfortunately, with Maven 3.3.9 this simply doesn't work, the effective
> pom shows it as unresolved:
> 
> <grandparent.version>${project.parent.parent.version}</grandparent.version>
> 
> I can reproduce it with any new probject a simple way is, for example,
> using a spring boot project (which should have a parent
> (spring-boot-parent) and a grandparent (spring-boot-dependencies):
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <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>
> 
> 	<groupId>com.example</groupId>
> 	<artifactId>demo</artifactId>
> 	<version>0.0.1-SNAPSHOT</version>
> 	<packaging>jar</packaging>
> 
> 	<parent>
> 		<groupId>org.springframework.boot</groupId>
> 		<artifactId>spring-boot-starter-parent</artifactId>
> 		<version>1.4.2.RELEASE</version>
> 		<relativePath/> <!-- lookup parent from repository -->
> 	</parent>
> 
> 	<properties>
> 		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
> 
> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
> 		<java.version>1.8</java.version>
> 
> <grandparent.version>${project.parent.parent.version}</grandparent.version>
> </properties>
> 	
> </project>
> 
> Any ideas how to access the parent.parent.version otherwise?
> Unfortunately, I only found closed issues where
> ${project.parent.parent.version} was given as a workaround...
> 



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