java - 是否可以在自定义的 Maven 原型(prototype)中提供动态目录结构

标签 java maven maven-archetype

我创建了一个新的 Maven 原型(prototype),以便它生成我的自定义项目结构。为此,我创建了一个项目,其中包含要生成的 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>

这按预期工作,我能够使用此原型(prototype)创建一个新的 Maven 项目。 现在我想创建一个动态目录结构。与中一样,我想在文件集中创建一个名为 ${artifactId} 的目录。即有点像 -

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

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

是否可以给出这样的动态目录结构?

最佳答案

似乎这是一个应该在几年前就已经修复的错误。可能现在又出现了错误?

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

另见 Maven archetype not using properties to create module names并就解决方法进行了一些讨论。

关于java - 是否可以在自定义的 Maven 原型(prototype)中提供动态目录结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42062039/

相关文章:

java - 为什么我们使用 struts 标签而不是旧的 HTML 标签,它带来什么区别?

hibernate - 找不到 org.hibernate :hibernate-dependencies:pom:3. 3.2.GA 失败

spring - Maven 过滤依赖项中存储的资源

maven-3 - 使用junit 4创建POM

scala - Maven 的最新 Scala 原型(prototype)

java - 为什么 "Ꙭ".codePointAt(0)==205 和其他 Java 字符奇怪?

java - 使用 Mockito 和 PowerMock 模拟私有(private)方法

maven-2 - 命名使用 Maven Archetype 生成的项目的根目录

Java 线程 : Using sleep and interrupt rather than wait and notifyAll

java - 如何使用量规在规范中的场景之间传递动态数据