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

这是我项目的结构

  -Root
  -    webapps
  -          module1
  -          module2

我有针对根和模块的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>

在模块2中,它类似于模块1。

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

但是,当我去模块1并运行pom.xml时,问题就会发生。然后也这样做也是如此:触发root pom.xml和module1的pom.xml。我不喜欢这个。 What i want to be happened is ONLY the module1's pom file is triggered (仅构建模块1),不会触发root的pom(不构建根项目)。

请任何帮助。

有帮助吗?

解决方案

更新: 如果您不希望插件配置在POM中应用,该POM从声明的POM继承,请设置 inheritedfalse.

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

参考


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

$ tree .
.
├── pom.xml
└── webapps
    ├── module1
    │   ├── pom.xml
    │   └── src
    │       └── main
    │           └── webapp
    │               ├── index.jsp
    │               └── WEB-INF
    │                   └── web.xml
    └── module2
        ├── pom.xml
        └── src
            └── main
                ├── resources
                └── webapp
                    ├── 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 install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] Q3790987
[INFO] module1 Maven Webapp
[INFO] module2 Maven Webapp
[INFO] 
[INFO] ------------------------------------------------------------------------
...

但是建立孩子并不会触发父母的任何东西:

$ cd webapps/module1/
$ mvn install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building module1 Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
...

一切都按照我的期望工作。


(在看来我误解了这个问题时,最初的答案被删除了)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top