views:

21

answers:

2

Hi all,

I have a POM which declares web application stuff that is common to my projects. I use this as the parent for all web applications.

Is it possible to activate a profile only when the packaging is war? I have tried the property approach, but that doesn't work (as it isn't a system/environment property).

Since this fails the build, I can simply disable that profile when installing the POM, but I'd like it to be more intelligent on its own.

Walter

A: 

I know this isn't answering your question directly, but the usual workaround for problems like this is to just use specialization (as with classes).

So you have your MasterPom with all common behavior.

MasterWarPom that extends MasterPom (is it's parent), and put any 'packing is war' specializations in here.

Likewise you could have MasterJarPom, etc ...

That way the differences are split out nicely.

lucas1000001
That is exactly what I'm doing. This is my abstract web application pom, the problem is, the key generation part wants to run on the package phase. What I do when I install/deploy the pom is disable that profile.
+1  A: 

There's no clean way to do that, the parent module has no way of knowing the child's packaging. (Non-clean solutions would involve creating a plugin that parses the child module's pom etc.)

seanizer
Why can't a simple activation do? For instance, in the parent pom, you say, activate when project.packaging = war or jar. When the child's packaging overrides the parent's packaging of pom, then the profile is activated. Would it be possible to write such an activation?
I am pretty sure that is not how profile inheritance works. The parent will switch on the profile or not, but the child will not inherit the switching-on logic, only what's inside the profile.
seanizer