是否可以在自定义maven原型中提供动态目录结构

时间:2017-02-06 07:03:27

标签: java maven maven-archetype

我创建了一个新的maven原型,以便生成我的自定义项目结构。为此,我创建了一个项目,其中包含要生成的archetype-metadata.xml和pom.xml。

在META-INF / maven下我有archetype-metadata.xml文件 -

    <?xml version="1.0" encoding="UTF-8"?>
       <archetype-descriptor xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd" name="test"
    xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <fileSets>
            <fileSet filtered="true" encoding="UTF-8">
              <directory>com/test/MyProject</directory>
              <includes>
                 <include>.classpath</include>
                 <include>.project</include>
              </includes>
           </fileSet>
          </fileSets>
       </archetype-descriptor>

和archetype-resources / pom.xml -

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>${groupId}</groupId>
  <artifactId>${artifactId}</artifactId>
  <version>${version}</version>
  <packaging>jar</packaging>
</project>

这是按预期工作的,我可以使用此原型创建一个新的maven项目。 现在我想创建一个动态目录结构。在中,我想在fileset中创建一个名为$ {artifactId}的目录。有点像 -

 <fileSet filtered="true" encoding="UTF-8">
     <directory>com/test/${artifactId}</directory>
      <includes>
         <include>.classpath</include>
          <include>.project</include>
      </includes>
  </fileSet>

我试过这个answer,但我无法实现它。

是否可以提供这样的动态目录结构?

1 个答案:

答案 0 :(得分:1)

似乎这是一个错误,应该已经修复了几年。可能现在再次出现这个错误?

https://issues.apache.org/jira/browse/ARCHETYPE-191

另请参阅Maven archetype not using properties to create module names,并就变通方法进行一些讨论。