5

We would like to create a partial archetype to add a custom-pom.xml as well as other resources into an existing project. The custom pom will then be used in the generated project via mvn -f custom-pom.xml.

Our archetype therefore contains a src/main/resources/archetype-resources/osgi-pom.xml, but does not contain a pom.xml in the same directory.

We used archetype:generate parameterised appropriately to run this archetype on an existing project. This produces:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli) on project standalone-pom: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Unable to find resource 'archetype-resources/pom.xml' -> [Help 1]

As a test, we created a dummy archetype-resources/pom.xml then re-ran the generate goal. This produces:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:generate (default-cli) on project standalone-pom: Don't override file /tmp/archetype/fabric-rf-server/pom.xml -> [Help 1]

We saw this example which has no archetype-resources/pom.xml. We are using the Archetype 2.0x standard however, which is possibly why the tactic works for that author but not ourselves.

How can we resolve this problem? Is a partial archetype unsuitable for inserting resources into an existing Maven project - must the project instead be non-Maven?

We've scoured the Maven Archetype plugin 2.2 documentation but there's barely any mention of partial archetypes and their specialised behaviour.

KomodoDave
  • 7,239
  • 10
  • 60
  • 92

3 Answers3

4

It turns out the second error message listed in OP is because of conflicting POM properties (the artifactId, groupId and version). Removing these from the archetype-resources/pom.xml solved the issue.

What actually happens with a partial archetype is the existing project has its POM merged with that in the archetype. So this property conflict was causing the merge to fail.

We identified that a merge should occur after exploring the source code.

KomodoDave
  • 7,239
  • 10
  • 60
  • 92
  • Maven seems to be suffering form some serious bipolar disorder. If I give it archetype-resources/pom.xml, it tells me not to rewrite it. If I don't give it, it tells me that it needs it. If I give it but empty, it complains that it doesn't start with . If I start it with it just goes back to step 1 and tells me not to rewrite pom.xml. How did you get away from this catch22? – kaqqao Jun 07 '15 at 22:28
  • @kaqqao Not sure, this was a long time ago. I still have the working file - when you add `` I presume you're including all the usual namespace guff etc.? So my working one starts with this: ` 4.0.0 ` – KomodoDave Jun 08 '15 at 08:09
0

Per Don't override file error, that's because there is one or more overlapping filesets, configured to copy same files into same location, Check your archetype's "achetype-metadata.xml", remove the duplicated config would solve this issue

for below instance, if there is a test.xml in config folder, it will be processed twice by velocity, and for second process it will print warning. if the file is pom.xml, it will cause build error

 <fileSet filtered="true" encoding="UTF-8">
  <directory>config/src</directory>
  <includes>
    <include>**/*.vm</include>
    <include>**/*.xml</include>
  </includes>
</fileSet>
<fileSet filtered="true" encoding="UTF-8">
  <directory>config</directory>
  <includes>
    <include>**/*.xml</include>
  </includes>
</fileSet>
Frank Zhang
  • 800
  • 11
  • 11
0

Don't override file error, because there is one or more overlapping filesets.

Removing the duplicated filesets would solve the problem.

mfaerevaag
  • 730
  • 5
  • 29