Embracing the Messiness in Search of Epic Solutions

Maven Archetype Plugin: Velocity Variable Substitutions Not Resolving

Posted

in

PROBLEM

Let’s assume we have the following package.json in our archetype:-

{
  "name": "${rootArtifactId}",
  "private": true,
  "devDependencies": {
    ...
  }
}

When creating a project from this archetype, the Velocity variable substitution for ${rootArtifactId} doesn’t resolve at all.

SOLUTION

After reading Maven Archetype Plugin’s source code here and here, the Velocity variable substitutions are only performed on the following file extensions:-

List<String> DEFAULT_FILTERED_EXTENSIONS =
    Arrays.asList(
        new String[]
            {
                "java", "xml", "txt", "groovy", "cs", "mdo", "aj", "jsp", "gsp",
                "vm", "html", "xhtml", "properties", ".classpath", ".project"
            }
    );

In another word, if we have these variables in JSON or JavaScript files, they will not resolved at all.

To fix this, define the needed file extensions in Maven Archetype Plugin configuration:-

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-archetype-plugin</artifactId>
    <version>2.3</version>
    <configuration>
        <archetypeFilteredExtentions>js,json,md,java,xml,txt,groovy,jsp,vm,html,properties</archetypeFilteredExtentions>
    </configuration>
</plugin>

Comments

Leave a Reply