I have a project with the following structure:
project (pom)
project-client (module, jar)
project-ejb (module, jar)
project-web (module, war)
project-ear (module, ear)
Inside the pom the modules reference the parent using:
<relativePath>../project</relativePath>
And the root pom references the modules the same way (using ../).
I can create an archetype using archetype:create-from-project, and everything runs smoothly.
But when I try to install the archetype (mvn install inside the target/generated-sources/archetype dir), I get the error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:integration-test (default-integration-test) on project seguranca-archetype:
[ERROR] Archetype IT 'basic' failed: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Unable to find resource 'archetype-resources/../__rootArtifactId__-client/pom.xml'
[ERROR] -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-archetype-plugin:2.2:integration-test (default-integration-test) on project seguranca-archetype:
Archetype IT 'basic' failed: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Unable to find resource 'archetype-resources/../__rootArtifactId__-client/pom.xml'
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException:
Archetype IT 'basic' failed: org.apache.maven.archetype.exception.ArchetypeGenerationFailure: Error merging velocity templates: Unable to find resource 'archetype-resources/../__rootArtifactId__-client/pom.xml'
at org.apache.maven.archetype.mojos.IntegrationTestMojo.execute(IntegrationTestMojo.java:268)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
The problem is that the file exists (it's on target/generated-sources/archetype/src/main/resources/__rootArtifactId__client/pom.xml), and I tried to fiddle with the archetype-metadata.xml with no success. Any clues?
Thanks in advance
It looks like the archetype plugin doesn't support flat layout for multi-module projects. If that is your case a workaround is to change to a nested layout. I did it by moving the modules outside the archetype-resources directory into it. Like this:
Before:
pom.xml
src
├── main
│ └── resources
│ ├── archetype-resources
│ │ └── pom.xml
│ ├── META-INF
│ │ └── maven
│ │ └── archetype-metadata.xml
│ ├── __rootArtifactId__.module1
│ │ ├── pom.xml
│ │ └── ...
│ ├── __rootArtifactId__.module2
│ │ ├── pom.xml
│ │ └── ...
│ ├── __rootArtifactId__.module3
│ ├── pom.xml
│ └── ...
│
└── test
└── resources
└── projects...
After:
pom.xml
src
├── main
│ └── resources
│ ├── archetype-resources
│ │ ├── pom.xml
│ │ ├── __rootArtifactId__.module1
│ │ │ ├── pom.xml
│ │ │ └── ...
│ │ ├── __rootArtifactId__.module2
│ │ │ ├── pom.xml
│ │ │ └── ...
│ │ └── __rootArtifactId__.module3
│ │ ├── pom.xml
│ │ └── ...
│ └── META-INF
│ └── maven
│ └── archetype-metadata.xml
└── test
└── resources
└── projects...
And then you edit any reference to the modules in archetype-metadata.xml, removing the '..' relative path.