Maven原型插件 - 如何使用不包含pom.xml的部分原型?

5
我们希望创建一个部分原型,将custom-pom.xml和其他资源添加到现有项目中。然后在生成的项目中通过mvn -f custom-pom.xml使用自定义pom。
因此,我们的原型包含src/main/resources/archetype-resources/osgi-pom.xml,但在相同目录中不包含pom.xml
我们使用适当参数化的archetype:generate在现有项目上运行此原型。这会产生:
[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]

作为测试,我们创建了一个虚拟的archetype-resources/pom.xml,然后重新运行generate目标。这将产生:
[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]

我们看到了这个例子, 它没有archetype-resources/pom.xml。然而,我们正在使用Archetype 2.0x标准,可能是为什么该作者的策略适用于他自己,但不适用于我们的原因。
我们如何解决这个问题?部分原型是否不适合向现有的Maven项目中插入资源 - 相反,项目必须是非Maven的?
我们已经搜索了Maven Archetype plugin 2.2文档,但几乎没有提到部分原型及其专门行为。
3个回答

4

原来,OP列出的第二个错误信息是由于POM属性冲突(artifactIdgroupIdversion)引起的。从archetype-resources/pom.xml中删除这些属性解决了这个问题。

部分原型实际上会将现有项目的POM与原型中的POM合并。因此,这种属性冲突导致合并失败。

通过探索源代码,我们确定应该进行合并。


Maven似乎患有严重的双相障碍。如果我给它archetype-resources/pom.xml,它会告诉我不要重写它。如果我不给它,它会告诉我需要它。如果我给了它但是为空,它会抱怨它不以<project>开头。如果我以<project>开头,它就回到第一步并告诉我不要重写pom.xml。你是如何摆脱这个进退两难的局面的? - kaqqao
@kaqqao 不确定,这是很久以前的事了。我仍然有工作文件 - 当您添加<project>时,我假设您包括所有通常的命名空间等内容?因此,我的工作文件从以下内容开始:<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> - KomodoDave

0

关于不要覆盖文件错误,这是因为有一个或多个重叠的文件集被配置为将相同的文件复制到相同的位置,请检查您的原型的"achetype-metadata.xml",删除重复的配置即可解决此问题。

例如,在下面的实例中,如果在配置文件夹中有一个test.xml文件,则它将被Velocity处理两次,并且对于第二次处理,它将打印警告。如果文件是pom.xml,则会导致构建错误。

 <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>

0

不要覆盖文件错误,因为存在一个或多个重叠的文件集。

删除重复的文件集将解决问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接