【问题标题】:multi-modules project with maven is not working as expected?使用 maven 的多模块项目没有按预期工作?
【发布时间】:2011-04-17 00:00:42
【问题描述】:

嗨 我正在尝试使用 m2eclipse 在 eclipse 中创建一个多模块项目。我遵循了一些教程,但它的工作方式不是我所期望的:

这是我项目的结构

  -Root
  -    webapps
  -          module1
  -          module2

我有用于 Root 和模块的 pom.xml。 (模块 1 和模块 2 相互独立) 在 pom.xml (Root) 中,我有

 <modules>
        <module>./webapps/module1</module>
        <module>./webapps/module2</module>
 </modules>

在module1的pom.xml中:

<parent>
        <groupId>{RootGroupId}</groupId>
        <artifactId>{RootArtifactId}</artifactId>
        <version>{RootVersionId}</version>
        <relativePath>../../pom.xml</relativePath>
    </parent>

在module2中,与module 1类似。

当我转到 Root 并运行 pom 文件时,它将首先触发 Root 的阶段,然后触发模块的阶段(构建根项目并构建模块项目)。对我来说很好。

但是当我转到 module1 并运行 pom.xml 时,就会出现问题。然后它也这样做:触发 Root pom.xml 和 module1 的 pom.xml。我不喜欢这个。 What i want to be happened is ONLY the module1's pom file is triggered(只建module1),不会触发root的pom(不建root项目)。

请帮忙。

【问题讨论】:

  • 你应该接受一些答案(在答案的投票计数器下方打勾)

标签: eclipse maven-2 project m2eclipse multi-module


【解决方案1】:

更新:如果您不想在从声明它的 POM 继承的 POM 中应用插件配置,请将 inherited 设置为 @987654324 @。

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>properties-maven-plugin</artifactId>
    <version>1.0-alpha-1</version>
    <inherited>false</inherited> <!-- THIS SHOULD DO IT -->
    <executions>
      <execution>
        <id>read-project-properties</id>
        <phase>initialize</phase>
        <goals>
          <goal>read-project-properties</goal>
        </goals>
        <configuration>
          <files>
            <file>build.properties</file>
          </files>
        </configuration>
      </execution>
    </executions>
  </plugin>

参考


我试图重现该问题...但没有成功。我创建了一个类似的项目结构:

$树。 . ├── pom.xml └── 网页应用 ├── 模块1 │   ├── pom.xml │   └── src │   └── 主要 │   └── webapp │   ├── index.jsp │   └── WEB-INF │   └── web.xml └── 模块2 ├── pom.xml └── 源 └── 主要 ├── 资源 └── 网页应用 ├── index.jsp └── WEB-INF └── web.xml

父 pom.xml 声明的地方:

  <modules>
    <module>webapps/module1</module>
    <module>webapps/module2</module>
  </modules>

还有每个孩子:

  <parent>
    <artifactId>Q3790987</artifactId>
    <groupId>com.stackoverflow</groupId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../../pom.xml</relativePath>
  </parent>

从根开始构建会触发反应器构建:

$ mvn安装 [INFO] 正在扫描项目... [信息] --------------------------------------------- ------------------------- [INFO] 反应堆建造顺序: [信息] [信息] Q3790987 [信息] 模块 1 Maven Webapp [信息] 模块 2 Maven Web 应用程序 [信息] [信息] --------------------------------------------- ------------------------- ...

但是建立一个孩子并不会在父母身上触发任何事情:

$ cd webapps/module1/ $ mvn安装 [INFO] 正在扫描项目... [信息] [信息] --------------------------------------------- ------------------------- [信息] 构建模块 1 Maven Webapp 1.0-SNAPSHOT [信息] --------------------------------------------- ------------------------- ...

一切正常。


(最初的答案被删除,因为我似乎误解了这个问题)

【讨论】:

  • 对不起,为此。我使用 {RootGroupId}, {artifactId} 只是为了简单起见。在真正的 Pom 文件中,我当然会对其进行硬编码。 Pom 运行良好,没有错误。唯一的问题是它没有按我的预期工作。
  • 谢谢帕斯卡。这是下载我的项目的链接(只有 7KB),请您看一下:uploading.com/files/f3d233cd/mvn-multimodules.zip。基本上,在父 pom 文件中,我有一个插件来读取 build.properties 文件,它将在初始化阶段被触发。但是当我转到module1并运行mvn初始化时,它也会触发读取属性文件过程。
  • 谢谢帕斯卡。你真好
猜你喜欢
  • 2018-05-25
  • 2020-07-24
  • 1970-01-01
  • 2021-10-27
  • 1970-01-01
  • 1970-01-01
  • 2018-09-11
  • 2013-07-02
  • 2019-08-08
相关资源
最近更新 更多