javamaven

How to specify maven properties in a aggregator POM?


I have a project structure like below.In aggregator POM project1 and project 2 are defined as modules.Now if i want to add a maven property that can be accessed in all the projects how can i do it?. What is the best project structure in this case.?

If i define property like <temp.dir>data</temp.dir> in the aggregator POM then it is not available in project1 pom.xml and project2 POM.xml.I have to duplicate the same property in both the POM's.

project
- project1
- - pom.xml  ---- has parent POM as project A
- project2
- - pom.xml  --- has parent POM as project B
- pom.xml (Aggregator POM)

UPDATE:To clarify more project1 pom and project 2 has different parent POM's.So aggregator POM cannot be set as parent.


Solution

  • You need to set the aggregator pom as the parent of project1 and project2. eg. in project1 and project2 poms add:

    <parent>
        <groupId>com.agr</groupId>
        <artifactId>project-aggregator</artifactId>
        <version>1.0.0</version>
    </parent>
    

    EDIT:

    I understand that project1 and project2 have different parent poms.

    The only solution i know about to achieve what You want is to store the properties in parent pom.

    I can think only of one solution, to make an inheritance chain:

    Project2Parent:

    <parent>
        <groupId>com.test</groupId>
        <artifactId>Project1Parent</artifactId>
        <version>0.0.1</version>
    </parent>
    <artifactId>Project2Parent</artifactId>
    <version>0.0.1</version>
    

    Aggregator:

    <parent>
        <groupId>com.test</groupId>
        <artifactId>Project2Parent</artifactId>
        <version>0.0.1</version>
    </parent>
    <artifactId>Aggregator</artifactId>
    <version>0.0.1</version>
    

    Project1

    <parent>
        <groupId>com.test</groupId>
        <artifactId>Aggregator</artifactId>
        <version>0.0.1</version>
    </parent>
    <artifactId>project1</artifactId>
    <version>0.0.1</version>
    

    Project2

    <parent>
        <groupId>com.test</groupId>
        <artifactId>Aggregator</artifactId>
        <version>0.0.1</version>
    </parent>
    <artifactId>project2</artifactId>
    <version>0.0.1</version>