Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven archetype not using properties to create module names

I created an archetype where you can set the moduleName (or expect to) using a required property moduleName, here is the archetype metadata xml (reduced, which I also tried with similar results)

<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor name="modules-archetype">

  <requiredProperties>
    <requiredProperty key="moduleName">
    </requiredProperty>
  </requiredProperties>

  <modules>
    <module id="modules-${moduleName}-api" 
            dir="modules-__moduleName__-api" 
            name="modules-${moduleName}-api">
      <fileSets>
        <fileSet encoding="UTF-8">
          <directory>src/main/java</directory>
        </fileSet>
      </fileSets>
    </module>
  </modules>

</archetype-descriptor>

After installing and generating, the moduleName value is not used in the directory name or the artifactid, the resuting values are

For the directory:        project/module-__moduleName__-api
For the pom/artifactId:   module-${moduleName}-api

The value is replaced correctly on some other files of the project, so no spelling problems I guess.

I've seen a lot of similar things, but all of them using rootArtifactId, and in fact if I use rootArtifactId (as the starting part of the name) it works as expected.

Not able to find a similar problem around, any idea why is it not working, or how to make it work?

like image 735
tonio Avatar asked Oct 10 '12 23:10

tonio


2 Answers

I found a reasonable work-around.

Seems the only place where you can only use the rootArtifactId is the <module> element in the archetype descriptor, but in every other place you can use the moduleName property without any trouble.

What I did:

Use ${moduleName} in

  • artifactId in module's pom
  • some default dependencies
  • The module definition in the main pom (<module>module-${moduleName}</module>)
  • etc.

Use __moduleName__ in

  • package name in src/main/java & resources

In the artifact descriptor

  • Use a fix module name something like module-sample1 & module-sample2 (and of course name the directories inside the artifact resources the same way).

Things to fix after the project is created

  1. The modules' directory name
  2. Take out the module elements in the main pom that contains module-sample[12]

All of this in a ant script embedded in a postcreate-pom.xml to be run after project creation.

And it worked smoothly.

Hope its useful for someone.

thanks to everybody that just take the time to read my question, tonio.

like image 149
tonio Avatar answered Oct 25 '22 10:10

tonio


archetype-metadata.xml and the pom.xml of the sub-module:

<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor name="multi-module">

  <modules>
    <module name="${rootArtifactId}-ria" id="${rootArtifactId}-ria" dir="__rootArtifactId__-ria">
      <fileSets>
        <fileSet filtered="true" packaged="true">
          <directory>src/main/java</directory>
          <includes>
            <include>**/*.java</include>
          </includes>
        </fileSet>
        <fileSet filtered="true" packaged="true">
            <include>pom.xml</include>
        </fileSet>
      </fileSets>
    </module>
  </modules>


</archetype-descriptor>
<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>

  <parent>
    <groupId>${groupId}</groupId>
    <artifactId>${rootArtifactId}</artifactId>
    <version>${version}</version>
  </parent>

  <artifactId>${artifactId}</artifactId>
  <packaging>war</packaging>

</project>
like image 44
sgpalit Avatar answered Oct 25 '22 08:10

sgpalit