自定义Maven原型不会生成archtype.xml中定义的源

时间:2019-01-10 17:06:06

标签: java maven maven-archetype

我正在尝试创建一个自定义原型,该原型定义了一个实质性的pom.xml并包括几个源文件。

使用此原型生成项目时,不会包含我在archetype.xml中定义的任何来源(pom.xml会按预期生成)。

我的archetype.xml位于src / main / resources / META-INF / maven中,并定义了两个源。

<archetype xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype/1.0.0 http://maven.apache.org/xsd/archetype-1.0.0.xsd">
<id>custom-archetype</id>

<sources>       
    <source>src/main/java/App.java</source>
</sources>
<resources>
    <resource>src/test/java/BatFile.bat</resource>
</resources>
</archetype>

App.java位于src / main / resources / archetype-resources / src / main / java中。

BatFile.bat位于src / main / resources / archetype-resources / src / main / resources中。

我在src / main / resources / META-INF / maven中也有一个archetype-metadata.xml,用于定义依赖项版本

<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor name="custom">
    <requiredProperties>
        <requiredProperty key="thorntail-version">
            <defaultValue>2.2.1.Final</defaultValue>
        </requiredProperty>
    </requiredProperties>
</archetype-descriptor>

我的根pom.xml如下

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

<groupId>uk.co.xxxxx</groupId>
<artifactId>custom-archetype</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Custom Archetype</name>
<description>Archetype for Custom projects</description>
</project>

在创建自定义原型方面,我一直遵循行家Documentation的原则,据我所知,我做的一切正确。

这是运行mvn install的结果

[INFO] Scanning for projects...                                                   
[INFO]                                                                            
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreade
d.SingleThreadedBuilder with a thread count of 1                                  
[INFO]                                                                            
[INFO] ------------------------------------------------------------------------   
[INFO] Building Custom Archetype 0.0.1-SNAPSHOT                                  
[INFO] ------------------------------------------------------------------------   
[INFO]                                                                            
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ custom-archetype ---                                                                         
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!                                                   
[INFO] Copying 6 resources                                                        
[INFO]                                                                            
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ custom-archetype ---                                                                            
[INFO] Nothing to compile - all classes are up to date                            
[INFO]                                                                            
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ custom-archetype ---                                                                 
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!                                                   
[INFO] Copying 0 resource                                                         
[INFO]                                                                            
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile)  custom-archetype ---
[INFO] No sources to compile   
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ custom-archetype 
---                                                                              
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ custom-archetype ---
[INFO] --- maven-install-plugin:2.4:install (default-install) @ custom-archetype        
 ---
[INFO] Installing D:\dev\customarchetype\target\custom-archetype-0.0.1-SNAPSHOT.jar to C:\Users\xxxx\.m2\repository\uk\co\xxxxx\custom-archetype\0
.0.1-SNAPSHOT\custom-archetype-0.0.1-SNAPSHOT.jar                                
[INFO] Installing D:\dev\custom\customarchetype\pom.xml to C:\Users\xxxx\.m2\rep
ository\uk\co\xxxxx\custom-archetype\0.0.2-SNAPSHOT\custom-archetype-0.0.
1-SNAPSHOT.pom                                                                    
[INFO] ------------------------------------------------------------------------   
[INFO] BUILD SUCCESS                                                              
[INFO] ------------------------------------------------------------------------   
[INFO] Total time: 2.849 s                                                        
[INFO] Finished at: 2019-01-11T09:29:18+00:00                                     
[INFO] Final Memory: 8M/245M                                                      
[INFO] ------------------------------------------------------------------------   

我正在运行以下maven命令来生成我的项目

mvn archetype:generate -DarchetypeGroupId=uk.co.gamma.xxxxx -DarchetypeArtifactId=custom-archetype -DarchetypeVersion=0.0.1-SNAPSHOT -DgroupId=uk.co.xxxxx -Dversion=0.0.1-SNAPSHOT -DartifactId=test12 -Dpackage=uk.co.xxxxx

这是输出

[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype repository not defined. Using the one from [uk.co.xxxxx:custom-archetype:0.0.1-SNAPSHOT] found in catalog local
[INFO] Using property: groupId = uk.co.xxxxx
[INFO] Using property: artifactId = test12
[INFO] Using property: version = 0.0.1-SNAPSHOT
[INFO] Using property: package = uk.co.xxxxx
[INFO] Using property: thorntail-version = 2.2.1.Final
Confirm properties configuration:
groupId: uk.co.xxxxx
artifactId: test12
version: 0.0.1-SNAPSHOT
package: uk.co.xxxxx
thorntail-version: 2.2.1.Final
 Y: :
[INFO] ----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype: custom-archetype:0.0.1-SNAPSHOT
[INFO] ----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: uk.co.xxxxx
[INFO] Parameter: artifactId, Value: test12
[INFO] Parameter: version, Value: 0.0.1-SNAPSHOT
[INFO] Parameter: package, Value: uk.co.xxxxx
[INFO] Parameter: packageInPathFormat, Value: uk/co/xxxxx
[INFO] Parameter: package, Value: uk.co.xxxxx
[INFO] Parameter: version, Value: 0.0.1-SNAPSHOT
[INFO] Parameter: thorntail-version, Value: 2.2.1.Final
[INFO] Parameter: groupId, Value: uk.co.xxxxx
[INFO] Parameter: artifactId, Value: test12
[INFO] Project created from Archetype in dir: D:\dev\testarchetype\test12
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.281 s
[INFO] Finished at: 2019-01-11T10:27:45+00:00
[INFO] Final Memory: 13M/183M
[INFO] ------------------------------------------------------------------------

生成的项目仅包含pom.xml。

从此原型生成项目时,我需要怎么做才能包含这些文件?

1 个答案:

答案 0 :(得分:0)

archetype-metadata.xml是原型2.x描述符,而archetype.xml是原型1.x描述符。同时使用这两种方法都将忽略archetype.xml中的任何内容。在archetype-metadata.xml中包含文件生成并删除archetype.xml可以解决此问题。