Project inheritance should work here: properties
are inherited if you place them in the parent pom and if the profile is activated. Please note that I said activated and not active for the current project (see MNG-3228 for the difference between both terms).
I've setup a simple multi-modules build demonstrating properties inheritance from a profile in the parent pom with maven 2.2.1. The project has the following structure:
.
|-- my-module
| |-- pom.xml
| `-- src
| |-- main
| | `-- java
| `-- test
| `-- java
`-- pom.xml
The parent pom.xml is defined as follow (adapted to my platform):
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>my-module</module>
</modules>
<profiles>
<profile>
<id>linux-x86</id>
<properties>
<someVar>some value</someVar>
</properties>
<activation>
<os>
<name>Linux</name>
<arch>i386</arch>
</os>
</activation>
</profile>
</profiles>
</project>
And this is the pom of the module:
<project>
<parent>
<artifactId>my-app</artifactId>
<groupId>com.mycompany.app</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-module</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<configuration>
<tasks>
<echo message="${someVar}"/>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
If I run Maven from the parent:
$ mvn help:active-profiles compile
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO] Unnamed - com.mycompany.app:my-app:pom:1.0-SNAPSHOT
[INFO] Unnamed - com.mycompany.app:my-module:jar:1.0-SNAPSHOT
[INFO] Searching repository for plugin with prefix: 'help'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.mycompany.app:my-app:pom:1.0-SNAPSHOT
[INFO] task-segment: [help:active-profiles] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [help:active-profiles {execution: default-cli}]
[INFO]
Active Profiles for Project 'com.mycompany.app:my-app:pom:1.0-SNAPSHOT':
The following profiles are active:
- linux-x86 (source: pom)
Active Profiles for Project 'com.mycompany.app:my-module:jar:1.0-SNAPSHOT':
There are no active profiles.
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.mycompany.app:my-app:pom:1.0-SNAPSHOT
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] No goals needed for project - skipping
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.mycompany.app:my-module:jar:1.0-SNAPSHOT
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/pascal/Projects/my-app/my-module/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
[echo] some value
[INFO] Executed tasks
[INFO]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Unnamed - com.mycompany.app:my-app:pom:1.0-SNAPSHOT ... SUCCESS [0.003s]
[INFO] Unnamed - com.mycompany.app:my-module:jar:1.0-SNAPSHOT SUCCESS [1.256s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Thu Oct 22 18:08:16 CEST 2009
[INFO] Final Memory: 9M/80M
[INFO] ------------------------------------------------------------------------
And if I run maven from the module:
$ cd my-module
$ mvn help:active-profiles compile
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'help'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.mycompany.app:my-module:jar:1.0-SNAPSHOT
[INFO] task-segment: [help:active-profiles] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [help:active-profiles {execution: default-cli}]
[INFO]
Active Profiles for Project 'com.mycompany.app:my-module:jar:1.0-SNAPSHOT':
There are no active profiles.
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - com.mycompany.app:my-module:jar:1.0-SNAPSHOT
[INFO] task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /home/pascal/Projects/my-app/my-module/src/main/resources
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [antrun:run {execution: default}]
[INFO] Executing tasks
[echo] some value
[INFO] Executed tasks
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Thu Oct 22 18:09:38 CEST 2009
[INFO] Final Memory: 10M/79M
[INFO] ------------------------------------------------------------------------
As you can see, the profile is activated (but not active) and the property defined in the profile in the parent pom is inherited.