tags:

views:

99

answers:

1

Suppose I have a module A:jar, which runtime and compilation set of dependencies depends on JDK version. In my example, I have a pre-jdk6-profile for JAXB API: prior to JDK 1.6.0 I need to include jaxb-api-nnn.jar as compile dependency. This profile is placed to A.pom.

I also have module B:war, which depends on A:jar. I want to be able to activate this profile on build server to build JDK 1.5.x deliverable. When I execute maven with given profile activated, I get the message:

mvn -Ppre-jdk6-profile -o install
[WARNING]
        Profile with id: 'pre-jdk6-profile' has not been activated.

and jaxb-api-nnn.jar is missing in resulting B.war. However if I activate this profile when building from parent pom, everything is OK. That means the profiles are not inherited from dependencies, and parent multi-module pom was able to build everything correctly because it seems like all profiles are merged in reactor.

Shifting the profile to parent pom makes things worse, as the dependencies are applied to all other projects (e.g. to C:ear). Are there nice solutions for this task, namely, if any module A depends on module B, then all compile and runtime dependencies which are activated by a profile, are correctly handled?

The profile in project A:jar follows:

<project ...>
    <artifactId>A</artifactId>
    <packaging>jar</packaging>
    ...
    <parent>
        <artifactId>P</artifactId>
        ...
    </parent>

    <profiles>
        <profile>
            <id>pre-jdk6-profile</id>

            <activation>
                <jdk>(,1.6.0)</jdk>
            </activation>

            <dependencies>
                <dependency>
                    <groupId>javax.xml.ws</groupId>
                    <artifactId>jaxws-api</artifactId>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
...
</project>
+1  A: 

a) In a multi-module build, you should always build from the top pom, never from an individual module. If you want to build only one module, use advanced reactor options (see mvn --help) like this:

mvn -pl mymodule

b) Define and activate the profile in the parent pom, but add the configuration in the child pom.

parent

<profiles>
    <profile>
         <id>pre-jdk-6</id>
         <activation>
            <jdk>(,1.6.0)</jdk>
         </activation>
    </profile>
</profiles>

child

<profiles>
    <profile>
        <id>pre-jdk6-profile</id>

        <dependencies>
            <dependency>
                <groupId>javax.xml.ws</groupId>
                <artifactId>jaxws-api</artifactId>
            </dependency>
        </dependencies>
    </profile>
</profiles>
seanizer
@seanizer: Do I need to add the 2nd part to module `A` or to module `B`?
dma_k
both. In the JAR with `<scope>provided</scope>`, in the webapp with default scope. But in both inside the profile.
seanizer
@seanizer: I believe, I can use only (b) if I run builds on Hudson. Thanks for you hints.
dma_k