Search code examples
mavenpropertiesprofile

maven profile uses wrong property in build


i have a pom file that generates a .war and i want to use 2 different profiles: ots and wiblatt

each of those profiles has a property (with the same name), which is used in jboss-web.xml: mailabo.ear

the two profiles look like this

<profiles>
    <profile>
        <id>ots</id>
        <properties>
            <mailabo.ear>mailabo-ots-ear-${project.version}</mailabo.ear>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.4</version>
                    <executions>
                        <execution>
                            <id>ots</id>
                            <phase>package</phase>
                            <goals>
                                <goal>war</goal>
                            </goals>
                            <configuration>
                                <classifier>ots</classifier>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <webResources>
                            <resource>
                                <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                                <filtering>true</filtering>
                                <targetPath>WEB-INF</targetPath>
                                <includes>
                                    <include>jboss-web.xml</include>
                                </includes>
                            </resource>
                        </webResources>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
    <profile>
        <id>wiblatt</id>
        <properties>
            <mailabo.ear>mailabo-wiblatt-ear-${project.version}</mailabo.ear>
        </properties>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>2.4</version>
                    <executions>
                        <execution>
                            <id>wiblatt</id>
                            <phase>package</phase>
                            <goals>
                                <goal>war</goal>
                            </goals>
                            <configuration>
                                <classifier>wiblatt</classifier>
                            </configuration>
                        </execution>
                    </executions>
                    <configuration>
                        <webResources>
                            <resource>
                                <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                                <filtering>true</filtering>
                                <targetPath>WEB-INF</targetPath>
                                <includes>
                                    <include>jboss-web.xml</include>
                                </includes>
                            </resource>
                        </webResources>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

this works fine:

mvn clean install -DskipTests -P ots => mailabo-web-1.0.1.9-SNAPSHOT-ots.war
where ${mailabo.ear} is correctly replaced with mailabo-ots-ear-1.0.1.9-SNAPSHOT

mvn clean install -DskipTests -P wiblatt => mailabo-web-1.0.1.9-SNAPSHOT-wiblatt.war
where ${mailabo.ear} is correctly replaced with mailabo-wiblatt-ear-1.0.1.9-SNAPSHOT

this doesn't work:

mvn clean install -DskipTests -P ots,wiblatt
generates mailabo-web-1.0.1.9-SNAPSHOT-ots.war
generates mailabo-web-1.0.1.9-SNAPSHOT-wiblatt.war
BUT all occurrences of ${mailabo.ear} contain mailabo-wiblatt-ear-1.0.1.9-SNAPSHOT

what i want os for the ots profile to contain the ots-specific property

can this somehow be resolved? does maven have some limitation where properties with the same name can't co-exist in one build call even if they are in different profiles? could i somehow define 2 properties with different names, and 2 jboss-web.xml files using one property each, and then depending on the profile include one or the other?


Solution

  • i ended up creating 2 jboss web xml files, each using a differently named property and then using the resources directive to move the web xmls into WEB-INF

    <profiles>
        <profile>
            <id>ots</id>
            <properties>
                <mailabo.ots.ear>mailabo-ots-ear-${project.version}</mailabo.ots.ear>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.4</version>
                        <executions>
                            <execution>
                                <id>ots</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>war</goal>
                                </goals>
                                <configuration>
                                    <classifier>ots</classifier>
                                    <webResources>
                                        <resource>
                                            <directory>${basedir}/src/main/module-specific/ots/webapp/WEB-INF</directory>
                                            <targetPath>WEB-INF</targetPath>
                                            <filtering>true</filtering>
                                            <includes>
                                                <include>jboss-web.xml</include>
                                            </includes>
                                        </resource>
                                    </webResources>
                                    <archive>
                                        <manifest>
                                            <addClasspath>true</addClasspath>
                                        </manifest>
                                    </archive>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>wiblatt</id>
            <properties>
                <mailabo.wiblatt.ear>mailabo-wiblatt-ear-${project.version}</mailabo.wiblatt.ear>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <build>
                <plugins>
                    <plugin>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.4</version>
                        <executions>
                            <execution>
                                <id>wiblatt</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>war</goal>
                                </goals>
                                <configuration>
                                    <classifier>wiblatt</classifier>
                                    <webResources>
                                        <resource>
                                            <directory>${basedir}/src/main/module-specific/wiblatt/webapp/WEB-INF</directory>
                                            <targetPath>WEB-INF</targetPath>
                                            <filtering>true</filtering>
                                            <includes>
                                                <include>jboss-web.xml</include>
                                            </includes>
                                        </resource>
                                    </webResources>
                                    <archive>
                                        <manifest>
                                            <addClasspath>true</addClasspath>
                                        </manifest>
                                    </archive>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>