Maven Archetype

Maven archetype overwrites parent information

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 2.0-alpha-5
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    1

Description

When creating a new archetype that I want to use for my projects I ran into some trouble with the created/copied pom.xml.

The archetype pom.xml (\src\main\resources\archetype-resources\pom.xml) looks like this:

<project>
  <parent>
		<groupId>group</groupId>
		<artifactId>masterpom</artifactId>
		<version>1.0</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>group</groupId>
  <artifactId>${artifactId}</artifactId>
  <version>1.0</version>
</project>

When I run my archetype it creates a pom.xml that looks like:

<project>
  <parent>
  <artifactId>integration</artifactId>
    <groupId>group</groupId>
    <version>1.0</version>
  </parent>
  <modelVersion>4.0.0</modelVersion>
  <groupId>group</groupId>
  <artifactId>test</artifactId>
  <version>1.0</version>
</project>

Where "integration" is the name of the pom in the folder that I'm running mvn archetype:create from.
Digging into the source we find in DefaultArchetype.java that processTemplate is indeed reading the parent pom and overwriting whatever was found in the original pom.xml.
Is this really what we want to achieve? It should be possible to keep the parent-pom from the pom.xml in the archetype since it reduces the need for all developers to change their newly created pom.xml.

processTemplates
 if ( parentModel != null )
        {
            Parent parent = new Parent();
            parent.setGroupId( parentModel.getGroupId() );
            if ( parent.getGroupId() == null )
            {
                parent.setGroupId( parentModel.getParent().getGroupId() );
            }
            parent.setArtifactId( parentModel.getArtifactId() );
            parent.setVersion( parentModel.getVersion() );
            if ( parent.getVersion() == null )
            {
                parent.setVersion( parentModel.getParent().getVersion() );
            }
            generatedModel.setParent( parent );

Two alternative solutions:

  • If the parent-pom is specified in the archetype-pom, don't replace it
  • A parameter that we can supply that will leave the archetype-pom parent setting untouched.

I vote for solution number 1....

Issue Links

Activity

Hide
Jeff Trimm added a comment -

+1 for Peter's first proposed alternative solution... we're using custom parent POM's and archetypes and getting bitten by this very same issue. "If the parent-pom is specified in the archetype-pom, don't replace it" makes perfect sense to us.

Show
Jeff Trimm added a comment - +1 for Peter's first proposed alternative solution... we're using custom parent POM's and archetypes and getting bitten by this very same issue. "If the parent-pom is specified in the archetype-pom, don't replace it" makes perfect sense to us.
Hide
Michael Sell added a comment - - edited

I too have run into this as we are creating an archetype of a multi-module project, where many of the individual projects have specific parent poms that are not included in the archetype. The files for the archetype seem to be created from the original as I would expect, but when we try to generate the project from the archetype later, all of the parents get overridden to be the aggregate pom of the generated project, rather than keeping their original parents. This is a blocker for my project..

Show
Michael Sell added a comment - - edited I too have run into this as we are creating an archetype of a multi-module project, where many of the individual projects have specific parent poms that are not included in the archetype. The files for the archetype seem to be created from the original as I would expect, but when we try to generate the project from the archetype later, all of the parents get overridden to be the aggregate pom of the generated project, rather than keeping their original parents. This is a blocker for my project..
Hide
Jason Voegele added a comment -

I too vote for Peter's first proposed alternative solution. This issue is preventing me from creating a usable multi-module archetype that doesn't require end-users to modify the pom.xml of the submodule.

Show
Jason Voegele added a comment - I too vote for Peter's first proposed alternative solution. This issue is preventing me from creating a usable multi-module archetype that doesn't require end-users to modify the pom.xml of the submodule.
Hide
Jason Voegele added a comment -

I've attached a very simple patch that implements the suggested alternative approach.

Show
Jason Voegele added a comment - I've attached a very simple patch that implements the suggested alternative approach.
Hide
Raphaël Piéroni added a comment -

Fixed since revision 722648
Thanks to Jason Voegele patch.

Show
Raphaël Piéroni added a comment - Fixed since revision 722648 Thanks to Jason Voegele patch.
Hide
Jeff Trimm added a comment -

We tried the alpha-5 snapshot and this is not fixed yet. The parent POM name/version/groupId is still getting stomped. Note: this is a multi-module project and the POM containing the parent declaration we want to preserve is in a sub-module. We used this version:
http://repository.apache.org/content/groups/snapshots-group/org/apache/maven/plugins/maven-archetype-plugin/2.0-alpha-5-SNAPSHOT/

Show
Jeff Trimm added a comment - We tried the alpha-5 snapshot and this is not fixed yet. The parent POM name/version/groupId is still getting stomped. Note: this is a multi-module project and the POM containing the parent declaration we want to preserve is in a sub-module. We used this version: http://repository.apache.org/content/groups/snapshots-group/org/apache/maven/plugins/maven-archetype-plugin/2.0-alpha-5-SNAPSHOT/
Hide
Bill Milligan added a comment -

Can anyone corroborate that this is still broken? If so, can we re-open the defect? I'm hacking around this issue in alpha-4 right now...

Show
Bill Milligan added a comment - Can anyone corroborate that this is still broken? If so, can we re-open the defect? I'm hacking around this issue in alpha-4 right now...
Hide
Jason Voegele added a comment -

Bill, I believe that the patch has been applied and the issue resolved, but the alpha-5 version that includes the fix has not been released yet. The archetype plugin maintainer(s) will need to cut a new release for this fix to be made available.

In the meantime, I have made a patched version of the archetype plugin that includes this fix and am hosting it in the Terracotta Maven repository. If you add http://www.terracotta.org/download/reflector/maven2 to your pom.xml (or settings.xml) you can then use the 2.0-alpha-5-parent-patch-SNAPSHOT version of the maven-archetype-plugin.

Show
Jason Voegele added a comment - Bill, I believe that the patch has been applied and the issue resolved, but the alpha-5 version that includes the fix has not been released yet. The archetype plugin maintainer(s) will need to cut a new release for this fix to be made available. In the meantime, I have made a patched version of the archetype plugin that includes this fix and am hosting it in the Terracotta Maven repository. If you add http://www.terracotta.org/download/reflector/maven2 to your pom.xml (or settings.xml) you can then use the 2.0-alpha-5-parent-patch-SNAPSHOT version of the maven-archetype-plugin.
Hide
Jeff Trimm added a comment -

Hey guys, any hope that archetype 2.0-alpha-5 will be released in short order? The parent-pom bug is painful, as is requiring hordes of developers to configure (and ultimately forget/neglect to configure) Jason Voegele's generous repo publication of 2.0-alpha-5-parent-patch-SNAPSHOT at the terracotta repo. This has been an open issue for 2 years!

-Jeff

Show
Jeff Trimm added a comment - Hey guys, any hope that archetype 2.0-alpha-5 will be released in short order? The parent-pom bug is painful, as is requiring hordes of developers to configure (and ultimately forget/neglect to configure) Jason Voegele's generous repo publication of 2.0-alpha-5-parent-patch-SNAPSHOT at the terracotta repo. This has been an open issue for 2 years! -Jeff

People

Vote (4)
Watch (6)

Dates

  • Created:
    Updated:
    Resolved: