0

I have a project which may take different sources / resources based on the selected profiles. Some profiles are mutually exclusive, some should be combinable, for example the profiles local and wildfly defined in the snippet below should be combinable

<profiles>
    <profile>
        <id>local</id>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <inherited>true</inherited>
                        <executions>
                            <execution>
                                <id>add-sources</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>add-source</goal>
                                </goals>
                                <configuration>
                                    <sources>
                                        <source>profiles/local/src/main/java</source>
                                    </sources>
                                </configuration>
                            </execution>
                            <execution>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>add-resource</goal>
                                </goals>
                                <configuration>
                                    <resources>
                                        <resource>
                                            <directory>profiles/local/src/main/resources</directory>
                                            <filtering>true</filtering>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </profile>

    <profile>
        <id>wildfly</id>
        <build>
            <pluginManagement>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>build-helper-maven-plugin</artifactId>
                        <inherited>true</inherited>
                        <executions>
                            <execution>
                                <id>add-sources</id>
                                <phase>generate-sources</phase>
                                <goals>
                                    <goal>add-source</goal>
                                </goals>
                                <configuration>
                                    <sources>
                                        <source>profiles/wildfly/src/main/java</source>
                                    </sources>
                                </configuration>
                            </execution>
                            <execution>
                                <phase>generate-resources</phase>
                                <goals>
                                    <goal>add-resource</goal>
                                </goals>
                                <configuration>
                                    <resources>
                                        <resource>
                                            <directory>profiles/wildfly/src/main/resources</directory>
                                            <filtering>true</filtering>
                                        </resource>
                                    </resources>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </pluginManagement>
        </build>
    </profile>
</profiles>

If I do this under eclipse I notice that only the latter is actually applied - I only see the sources / resources defined in the wildfly profile.

Also in the resulting complete POM I notice that only the latter (wildfly) profile's configuration is applied, thus removing the sources and the resource defined in the local profile.

Is this the way the plugin is supposed to work, or am I missing something?

Stefano Cazzola
  • 1,597
  • 1
  • 20
  • 36
  • Are there really source code differences for wildfly between local running and production? This should be handled by properties etc. but not in the code. – khmarbaise May 09 '17 at 12:19
  • @khmarbaise a bit OT, but fyi: nope, that's why the profiles need to be combinable. Wildfly, just as most app servers, has its own quirks (in my case, a property to set on JMS messages to delay its delivery). This code is very specific to handle such peculiarities on different app servers, while all other code is strictly standard. – Stefano Cazzola May 10 '17 at 19:35
  • Based on a base priciple I would make separate maven projects for the specific code which and produce different war/ear with the different module in there... – khmarbaise May 11 '17 at 07:27
  • @khmarbaise this would just shift the problem on the dependencies – Stefano Cazzola May 11 '17 at 12:02

1 Answers1

0

Ok.... It was just me.

I gave the executions the same name, hence they were overridden. My bad.

This question might be closed / removed by moderators.

Stefano Cazzola
  • 1,597
  • 1
  • 20
  • 36