Created archetype not creating folders under package

Viewed 195

Using Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)

Project is structured as:

My-archetype
| -- pom.xml
`--src
  `--main
    `resources
      |-- META-INF
         `--maven
             `--archetype-metadata.xml
       |--archetype-resources
          |--pom.xml
          |--log4j2.xml
          `--src
             |--main
             |   `--java
             |       `--App.java
             |        `--conf 

Note: conf is a directory

The project pom is

    <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
https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>demo</groupId>
  <artifactId>my-archetype</artifactId>
  <version>1</version>
  <packaging>maven-archetype</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
  </properties>

  <build>
    <extensions>
      <extension>
        <groupId>org.apache.maven.archetype</groupId>
        <artifactId>archetype-packaging</artifactId>
        <version>3.1.1</version>
      </extension>
    </extensions>
  </build>
</project>

The archetype-metadata.xml is:

<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor
xsi:schemaLocation="https://maven.apache.org/plugins/maven-archetype-plugin/
archetype-descriptor/1.1.0
http://maven.apache.org/xsd/archetype-descriptor-1.1.0.xsd" name="at"
xmlns="https://maven.apache.org/plugins/maven-archetype-plugin/archetype-des
criptor/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <fileSets>
    <fileSet filtered="true" encoding="UTF-8">
      <directory></directory>
      <includes>
        <include>changeme.gitignore</include>
        <include>log4j2.xml</include>
      </includes>
    </fileSet>
    <fileSet filtered="false" packaged="true" encoding="UTF-8">
      <directory>src/main/java</directory>
      <includes>
      <include>**/*.java</include>
      </includes>
    </fileSet>
    <fileSet filtered="false" packaged="false" encoding="UTF-8">
      <directory>toplevel</directory>
    </fileSet>
  </fileSets>
</archetype-descriptor>

When I build the project I (mvn install) there is one warning message of: [WARNING] No Archetype IT projects: root 'projects' directory not found.

I am in a windows 10 environment the batch file is:

mvn archetype:generate "-DarchetypeGroupId=demo"
"-DarchetypeArtifactId=my-archetype" "-DarchetypeVersion=1" "-DgroupId=demo"
"-DartifactId=at" "-Dpackage=d" "-Dversion=0.0.1-SNAPSHOT"
"-DinteractiveMode=false"

the output is:

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------< org.apache.maven:standalone-pom
>-------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] --------------------------------[ pom
]---------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.2.0:generate (default-cli) >
generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.2.0:generate (default-cli) <
generate-sources @ standalone-pom <<<
[INFO]
[INFO]
[INFO] --- maven-archetype-plugin:3.2.0:generate (default-cli) @
standalone-pom ---
[INFO] Generating project in Batch mode
[INFO] Archetype repository not defined. Using the one from
[demo:my-archetype:1] found in catalog local
[INFO]
----------------------------------------------------------------------------
[INFO] Using following parameters for creating project from Archetype:
my-archetype:1
[INFO]
----------------------------------------------------------------------------
[INFO] Parameter: groupId, Value: demo
[INFO] Parameter: artifactId, Value: at
[INFO] Parameter: version, Value: 0.0.1-SNAPSHOT
[INFO] Parameter: package, Value: d
[INFO] Parameter: packageInPathFormat, Value: d
[INFO] Parameter: package, Value: d
[INFO] Parameter: version, Value: 0.0.1-SNAPSHOT
[INFO] Parameter: groupId, Value: demo
[INFO] Parameter: artifactId, Value: at
[INFO] Project created from Archetype in dir:
C:\Users\pshan\eclipse-workspace\my-archetype\x\at
[INFO]
------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO]
------------------------------------------------------------------------
[INFO] Total time:  3.172 s
[INFO] Finished at: 2021-09-05T11:47:43-04:00
[INFO]
------------------------------------------------------------------------

The directory at \toplevel is created

The directory at\src\main\java\d is created and the file App.java is created and the package name is correctly placed in the file.

The issue is the directory conf is not being created at all. I am expecting it at at\src\main\java\d\conf

but it is not being created. What am I doing wrong?

One thing I did notice .. if I put a file like delme.txt and add **/*.txt to archetype-metadata the folder and file are created. However I am wanting just an empty folder.

1 Answers

I have an archetype that creates an empty directory. I don't specify that directory in archetype-resources/src/main though. Instead I have it in META-INF/maven/archetype-metadata.xml like this:

<fileSets>
    <fileSet filtered="true" encoding="UTF-8">
        <directory>src/main/scripts</directory>
    </fileSet>
</fileSets>

And I get an empty directory after using the archetype, as intended.

Related