Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Project inheritance should work here: <code>properties</code> are inherited if you place them in the parent pom <strong>and</strong> if the profile is activated. Please note that I said <em>activated</em> and not <em>active</em> for the current project (see <a href="http://jira.codehaus.org/browse/MNG-3228" rel="nofollow noreferrer">MNG-3228</a> for the difference between both terms). </p> <p>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:</p> <pre><code>. |-- my-module | |-- pom.xml | `-- src | |-- main | | `-- java | `-- test | `-- java `-- pom.xml </code></pre> <p>The parent pom.xml is defined as follow (adapted to my platform):</p> <pre><code>&lt;project&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;com.mycompany.app&lt;/groupId&gt; &lt;artifactId&gt;my-app&lt;/artifactId&gt; &lt;packaging&gt;pom&lt;/packaging&gt; &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt; &lt;modules&gt; &lt;module&gt;my-module&lt;/module&gt; &lt;/modules&gt; &lt;profiles&gt; &lt;profile&gt; &lt;id&gt;linux-x86&lt;/id&gt; &lt;properties&gt; &lt;someVar&gt;some value&lt;/someVar&gt; &lt;/properties&gt; &lt;activation&gt; &lt;os&gt; &lt;name&gt;Linux&lt;/name&gt; &lt;arch&gt;i386&lt;/arch&gt; &lt;/os&gt; &lt;/activation&gt; &lt;/profile&gt; &lt;/profiles&gt; &lt;/project&gt; </code></pre> <p>And this is the pom of the module:</p> <pre><code>&lt;project&gt; &lt;parent&gt; &lt;artifactId&gt;my-app&lt;/artifactId&gt; &lt;groupId&gt;com.mycompany.app&lt;/groupId&gt; &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt; &lt;/parent&gt; &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt; &lt;groupId&gt;com.mycompany.app&lt;/groupId&gt; &lt;artifactId&gt;my-module&lt;/artifactId&gt; &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt; &lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;artifactId&gt;maven-antrun-plugin&lt;/artifactId&gt; &lt;executions&gt; &lt;execution&gt; &lt;phase&gt;compile&lt;/phase&gt; &lt;configuration&gt; &lt;tasks&gt; &lt;echo message="${someVar}"/&gt; &lt;/tasks&gt; &lt;/configuration&gt; &lt;goals&gt; &lt;goal&gt;run&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt; &lt;/project&gt; </code></pre> <p>If I run Maven from the parent:</p> <pre><code>$ 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] ------------------------------------------------------------------------ </code></pre> <p>And if I run maven from the module:</p> <pre><code>$ 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] ------------------------------------------------------------------------ </code></pre> <p>As you can see, the profile is activated (but not active) and the property defined in the profile in the parent pom is inherited.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload