3

I know it's impossible to "chain" profile declaration. It's possible to do what I want (but not completely) with System properties in command line like mvn -Dvar=value . And then use this:

  <activation>
    <property>
      <name>var</name>
      <value>value</value>
    </property>            
  </activation>

or to activate simultaneously several profiles with -P profile1, profile2

In fact I have 4 profiles and I want to create a fifth profile with all the aspectj part (plugins, dependencies, ...) which should be activated only if profile 1, 2 or 3 is activated. Like that I don't have redundant plugins and dependencies declarations.

<profile>
  <id>profile1</id>
  <activation>
    <activeByDefault>true</activeByDefault>
  </activation>
  <build>
    ...     
  </build>
</profile>

<profile>
  <id>profile2</id>
  <build>
    ...     
  </build>
</profile>

<profile>
  <id>profile3</id>
  <build>
    ... 
  </build>
</profile>
<profile>
  <id>profile4</id>
  <build>
    <plugins>
      <plugin>
        ...
      </plugin>
    </plugins>
  </build>
</profile>

<profile>
  <id>aop</id>
  <build>
    <plugins>
      <plugin>
        ...
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
      ...
    </dependency>
    <dependency>
      ...
    </dependency>
  </dependencies>
</profile>

The problem is that profile 1 is the default profile and even it should be possible to do it without command line args. I tried with defining a value but it doesn't work because activation property only works with system properties.

Am I wrong? Is there another way to do it?

Thanks

HowHigH
  • 145
  • 1
  • 7

1 Answers1

2

Maven won't help you there, you can have no dependencies or inheritance between profiles, see also my recent answer to a related question.

You can explicitly turn profiles on or off, but there is no way to define any relation between them. Maven is not ant, which is usually a good thing, but this is one of the cases where I think it should be more like ant.

From Introduction to Build Profiles:

A profile can be triggered/activated in several ways:

  • Explicitly
  • Through Maven settings
  • Based on environment variables
  • OS settings
  • Present or missing files

None of these is helpful to define any relation between the profiles (Project properties can't be used because Profiles are evaluated while the Project is built). So your only options are to

  • live with the restrictions and explicitly activate the profiles you need using the -P syntax
  • write a shell script that encapsulates the maven call and automatically adds missing profiles
  • Build your own replacement for DefaultProfileSelector, as outlined in my previous answer
Community
  • 1
  • 1
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588
  • Hi Sean, thanks for your reply. I will look for the replacement for DefaultProfileSelector. They should let us define a property inside maven (${}) that we can check in the activation part or a mechanism of inheritance or aggregation with profile. – HowHigH Mar 17 '11 at 15:38