views:

34

answers:

1

Hi I am trying to create a multi-modules project in eclipse with m2eclipse. I followed some tutorials but the way it work is not what i expect:

Here is the structure of my project

  -Root
  -    webapps
  -          module1
  -          module2

I have pom.xml for Root and modules. (module 1 and 2 are independent to each other) In the pom.xml (Root), i have

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

In module1's pom.xml:

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

In module2, it is similar to module 1.

When I go to Root and run the pom file, it will trigger the Root's phases first and the module's phases later (build the root project and also build the module projects). To me it is fine.

But the problem happens when i go to module1 and run the pom.xml. Then it also so do the same: trigger the Root pom.xml and module1's pom.xml. i dont like this. What i want to be happened is ONLY the module1's pom file is triggered (ONLY module1 is built), root's pom will not be triggered (Root project is not be built).

Any help, please.

+2  A: 

Update: If you don't want a plugin configuration to be applied in POMs which inherit from the POM where it is declared, set inherited to false.

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

Reference


I tried to reproduce the problem... but didn't succeed. I created a similar project structure:

$ 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

Where the parent pom.xml declares:

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

And each child:

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

Building from the root triggers a reactor build:

$ mvn install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] Q3790987
[INFO] module1 Maven Webapp
[INFO] module2 Maven Webapp
[INFO] 
[INFO] ------------------------------------------------------------------------
...

But building a child doesn't trigger anything on the parent:

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

Everything works as expected for me.


(initial answer removed as it appeared I misinterpreted the question)

Pascal Thivent
Sorry, for this.i use {RootGroupId}, {artifactId} just for the sake of simplicity. In real Pom file, i, of course, hard-code it.The Pom is running fine, there is no error. The only thing is it not working as i expect.
David
Thanks Pascal. Here is the link to download my project (just 7KB), could you please take a look at it: http://uploading.com/files/f3d233cd/mvn-multimodules.zip/. Basically, in parent pom file, i have a plugin to read build.properties file, it will be triggled at initialize phase. But when i goto module1 and run mvn initialize, it also trigger the reading properties file process.
David
+1 for the effort.
Bozho
@Bozho Thanks :)
Pascal Thivent
Thanks Pascal. You are so nice
David