Search code examples
mavenmaven-archetype

Maven custom archetype - dockerfile not copied


I created a custom maven archetype. I created all the necessary directories

Inside the directory src/main/resources/archetype-resources i put all the default files and java sources I want to copy inside the generated project; between these files I have also Dockerfile and .gitignore files (not in a directory but in the root directory of the project) So I have this structure

custom maven archetype structure

I created also this archetype-metadata.xml

<archetype-descriptor
        xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.1.0 https://maven.apache.org/xsd/archetype-descriptor-1.1.0.xsd"
        name="${artifactId}">
    <requiredProperties>
        <requiredProperty key="artifactId">
            <defaultValue>artifact.id</defaultValue>
            <validationRegex>^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$</validationRegex>
        </requiredProperty>
        <requiredProperty key="artifactName">
            <defaultValue>artifact.name</defaultValue>
            <validationRegex>^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$</validationRegex>
        </requiredProperty>
        <requiredProperty key="artifactDescription">
            <defaultValue>artifact.descr</defaultValue>
            <validationRegex>^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$</validationRegex>
        </requiredProperty>
    </requiredProperties>

    <fileSets>
        <fileSet filtered="true" packaged="true" encoding="UTF-8">
            <directory>src/main/java</directory>
            <includes>
              <include>**/*.java</include>
              <include>*.java</include>
            </includes>
        </fileSet>
        <fileSet filtered="true" packaged="true" encoding="UTF-8">
            <directory>src/test/java</directory>
            <includes>
                <include>**/*.java</include>
                <include>*.java</include>
            </includes>
        </fileSet>
        <fileSet filtered="true" packaged="false" encoding="UTF-8">
            <directory>.</directory>
            <includes>
                <include>Dockerfile</include>
            </includes>
        </fileSet>
        <fileSet filtered="false" packaged="false" encoding="UTF-8">
            <directory>.</directory>
            <includes>
                <include>.gitignore</include>
            </includes>
        </fileSet>
    </fileSets>
</archetype-descriptor>

When I generate the project by executing mvn archetype:generate -B ..... I don't find the Dockerfile and .gitignore files in the generated project.

Any tips on how to solve this?


Solution

  • remove the dot in "directory" tags when you need to include some file in project root:

    <fileSet filtered="true" packaged="false" encoding="UTF-8">
         <directory></directory>
         <includes>
            <include>Dockerfile</include>
         </includes>
    </fileSet>