Maven Archetype Plugin - How to use a partial archetype containing no pom.xml?
Asked Answered
T

3

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.

Tinnitus answered 2/1, 2013 at 12:19 Comment(0)
T
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.

Tinnitus answered 2/1, 2013 at 12:59 Comment(2)
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 <project>. If I start it with <project> it just goes back to step 1 and tells me not to rewrite pom.xml. How did you get away from this catch22?Pushkin
@Pushkin Not sure, this was a long time ago. I still have the working file - when you add <project> I presume you're including all the usual namespace guff etc.? So my working one starts with this: <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> Tinnitus
C
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>
Cyprinodont answered 14/12, 2014 at 13:43 Comment(0)
A
0

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

Removing the duplicated filesets would solve the problem.

Alyss answered 13/11, 2017 at 2:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.