8

我创建了一个原型,您可以在其中使用必需的属性 moduleName 设置 moduleName(或期望),这是原型元数据 xml(减少,我也尝试过类似的结果)

<?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>

安装生成后,moduleName 值没有在目录名或artifactid 中使用,结果值为

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

该值在项目的其他一些文件上被正确替换,所以我猜没有拼写问题。

我见过很多类似的东西,但它们都使用 rootArtifactId,事实上,如果我使用 rootArtifactId(作为名称的开头部分),它会按预期工作。

找不到类似的问题,知道为什么它不起作用,或者如何使它起作用?

4

4 回答 4

4

我找到了一个合理的解决方法。

似乎您只能使用rootArtifactId的唯一地方是原型描述符中的 <module>元素,但在其他所有地方您都可以毫无问题地使用moduleName属性。

我做了什么:

在中使用${moduleName}

  • 模块的 pom 中的 artifactId
  • 一些默认依赖项
  • 主 pom 中的模块定义 (<module>module-${moduleName}</module>)
  • 等等

使用 __ moduleName __

  • src/main/java & 资源中的包名

工件描述符中

  • 使用类似于 module-sample1 和 module-sample2 的修复模块名称(当然,以相同的方式命名工件资源中的目录)。

创建项目后要修复的问题

  1. 模块的目录名称
  2. 取出主pom中包含module-sample[12]的模块元素

所有这些都在一个嵌入在 postcreate-pom.xml 中的 ant 脚本中,以便在项目创建后运行。

它工作顺利。

希望它对某人有用。

感谢所有花时间阅读我的问题的人,tonio。

于 2012-10-18T15:10:03.147 回答
3

archetype-metadata.xml 和子模块的 pom.xml:

<?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>
于 2015-03-17T16:29:04.027 回答
2

查看 maven-archetype 源(2.2 版),似乎唯一可能使用的值是从 DefaultFilesetArchetypeGenerator 中提取的 rootArtifactId

   while (subprojects.hasNext() ) {

        ModuleDescriptor project = subprojects.next();

        File moduleOutputDirectoryFile = new File( outputDirectoryFile
             , StringUtils.replace( project.getDir()
                   , "__rootArtifactId__"
                   , rootArtifactId 
                   ));
        ...........
于 2012-10-11T14:52:09.140 回答
1

从项目生成原型后,编辑文件target\generated-sources\archetype\src\main\resources\META-INF\maven\archetype-metadata.xml.

添加

    <fileSet filtered="true" packaged="true" encoding="UTF-8">
      <directory></directory>
      <includes>
        <include>pom.xml</include>
      </includes>
    </fileSet>

这将使它过滤您的 pom 文件!然后mvn install再次运行。

于 2013-05-13T16:58:51.457 回答