tags:

views:

10

answers:

2

[reduced for simplicity]

  • I have a project with several Maven modules
  • A module has a properties files whose contents are filtered during build
  • There are sets of properties that can be grouped
  • Only one group of properties exists in a given build
  • All groups have the same properties, only their values change between groups
  • parent
    +- pom.xml
    +- foo
       +- src/main/resources/test.properties
    

    I have set profiles in parent pom.xml. Each profile is activated by a command line argument and sets the values for the properties on that group.

    mvn clean compile -Dgroup1=true
    

    The problem is that I have to duplicate the entire profile between groups. I would like to only define the <properties> for each of the groups and use a single profile to control build order, plugins and other stuff.

    Anyone knows if that can be done?

    A: 

    I think this can be accomplished by using <pluginManagement>. You would declare build order, plugins and other stuff in the parent pom within <pluginManagement> section and then in each child, you would soecify the <plugin> along with the appropriate properties.

    Raghuram
    A: 

    That sounds to me like you want to just create a different set of property files for every profile, something like this:

    <profiles>
        <profile>
            <id>group1</id>
            <build>
                <filters>
                    <filter>src/main/resources/propertyfile1.txt</filter>
                    <filter>src/main/resources/propertyfile2.txt</filter>
                </filters>
            </build>
        </profile>
        <profile>
            <id>group2</id>
            <build>
                <filters>
                    <filter>src/main/resources/propertyfile3.txt</filter>
                    <filter>src/main/resources/propertyfile4.txt</filter>
                </filters>
            </build>
        </profile>
    </profiles>
    

    Now each profile gives you different values in resource filtering.


    If you also need the values in the pom, you will have to do some more processing, probably using the maven properties plugin or something similar. Put the meat of the plugin definition in the main build element:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>properties-maven-plugin</artifactId>
        <version>1.0-alpha-2</version>
        <executions>
            <execution>
                <phase>initialize</phase>
                <goals>
                    <goal>read-project-properties</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    And configure the loaded files in the individual profiles:

    <profile>
        <id>group1</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>properties-maven-plugin</artifactId>
                    <configuration>
                        <files>
                            <file>src/main/resources/propertyfile1.txt</file>
                            <file>src/main/resources/propertyfile2.txt</file>
                        </files>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
    
    seanizer