Пользовательский архетип maven не генерирует источники, определенные в archtype.xml - PullRequest
0 голосов
/ 10 января 2019

Я пытаюсь создать собственный архетип, который определяет существенный файл 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.

У меня также есть archetype-metadata.xml, расположенный в src / main / resources / META-INF / maven, который я использую для определения версии зависимости

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

Я слежу за maven Документация по созданию пользовательских архетипов и, насколько я вижу, я все делаю правильно.

Это результат запуска 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 голосов
/ 14 января 2019

archetype-metadata.xml является дескриптором архетипа 2.x, тогда как archetype.xml является дескриптором архетипа 1.x. Использование обоих означает что-либо в archetype.xml игнорируется. Включение создания файла в archetype-metadata.xml и удаление archetype.xml решает проблему.

...