问题
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.
回答1:
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.
回答2:
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>
回答3:
Don't override file error, because there is one or more overlapping filesets.
Removing the duplicated filesets would solve the problem.
来源:https://stackoverflow.com/questions/14121923/maven-archetype-plugin-how-to-use-a-partial-archetype-containing-no-pom-xml