Enable profile in dependent POM?


My company writes companion products for project management software that uses that software's Java API. They release new API versions with new releases of their products, and also point releases for bug fixes etc. We need to support clients using various versions of their software (and by extension, their API). In order to do this without unnecessary code duplication, we have defined profiles in our products that include the necessary dependencies for each API version.

I have a war project built using this technique with the "api70" profile activated, and another project that depends on that war project with a type of pom, in order to pull in the war's dependencies. The problem is that when building this second project, the profile-specific dependencies are not being included, even though I'm defining -Papi70 on the maven command line when building the depending project.

Is there any way to get this to work?

In the war project:

<!-- API 7.0 profile. -->




In the depending project:

<!-- Depend on war as type=pom for dependency mediation. -->

Command line used for building depending project:

mvn -P api70 clean package

The resulting build does not include integrationlibrary or any of its transitive dependencies.

I think that your problem doesn't apply to profiles at all. It's about how transitive dependencies work for war packaging. By design they doesn't work :) War archive contain its dependencies in WEB-INF/lib folder or if it is packaged in ear it can share libraries with ear libs. More of the problem you can read on this wiki article. It's about Skinny Wars but topic relates also your problem.

For you interesting is also this JIRA issue.

Quick but not elegant solution is to change packaging form war to pom (or create duplicate pom with pom packaging).