Maven原型插件-如何使用不包含pom.xml的部分原型? [英] Maven Archetype Plugin - How to use a partial archetype containing no pom.xml?

查看:122
本文介绍了Maven原型插件-如何使用不包含pom.xml的部分原型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们想创建一个局部原型,以将custom-pom.xml以及其他资源添加到现有项目中.然后,自定义pom将通过mvn -f custom-pom.xml用于生成的项目中.

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.

因此,我们的原型包含src/main/resources/archetype-resources/osgi-pom.xml,但在同一目录中不包含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.

我们使用适当地参数化的archetype:generate在现有项目上运行此原型.这将产生:

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]

作为测试,我们创建了一个虚拟archetype-resources/pom.xml,然后重新运行了generate目标.这将产生:

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.

我们如何解决此问题?部分原型是否不适合在现有Maven项目中插入资源-该项目必须不是非Maven吗?

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?

我们已经搜索了 Maven Archetype插件2.2文档,但几乎没有提及部分原型及其特殊行为的研究.

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

推荐答案

事实证明,OP中列出的第二条错误消息是由于POM属性(artifactIdgroupIdversion)冲突而引起的.从archetype-resources/pom.xml中删除它们可以解决此问题.

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.

部分原型实际发生的是现有项目的POM与原型中的POM合并.因此,此属性冲突导致合并失败.

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.

我们确定,在浏览源代码.

这篇关于Maven原型插件-如何使用不包含pom.xml的部分原型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆