mavenpackagemaven-archetypearchetypes

Maven archetype:generate forcing groupId as package structure


I'm trying to create an archetype to generate a Maven project with some properties that will be used in the files and with the file names and directory structure.

The problem I am running into is how to control the package directory structure? No matter what I have tried so far, the groupId I specify (which is a mandatory parameter in archetype:generate) forces itself as the package directory structure. If I try and have something different in my archetype-resources directory setup, or in the package name in the Java files themselves, I end up with whatever I specified there, AS WELL AS the groupId.

Effectively, I want my project structure to be different to my groupId, but the archetype generate seems to be forcing the groupId onto the package structure.

Is there a way to stop this?

If I use the following command:

archetype:generate -DarchetypeGroupId=archetype.test -DarchetypeArtifactId=archetype-test -DarchetypeVersion=1.0-SNAPSHOT -DgroupId=com.example.test.project-DartifactId=my.test.project.artifact -Dversion=1.0.0-SNAPSHOT

With the following fileset:

<fileSet filtered="true" packaged="true">
        <directory>src/main/java</directory>
        <includes>
            <include>**/MyClass.java</include>
        </includes>
    </fileSet>

I end up with my Java files being under:

src/main/java/com/example/test/project/MyClass.java.

I still want the same groupId, but I want my class to be in a separate directory, such as:

src/main/java/com/different/project/MyClass.java

Solution

  • See Create a Project from an Archetype – Batch mode:

    It is possible to call the Archetype Plugin to generate a project in batch mode (to get rid of the prompting). This is achieved by providing the Archetype Plugin with all the needed values as system properties.

    • ...

    • package specifies the package for the sources of the generated project

    • ...

    Long story short, add the following to your command line:

    -Dpackage=com.different.project