Where are the three places that I can specify profiles?
Author: Deron Eriksson
Description: This tutorial describes three ways to specify profiles in maven.
Tutorial created using: Windows Vista || JDK 1.6.0_04 || Eclipse Web Tools Platform 2.0.1 (Eclipse 3.3.1)


Page: < 1 2

(Continued from page 1)

To see the active profiles, I'll perform a 'mvn help:active-profiles' on the 'aproject' project. Notice that profiles.xml.profile, pom.xml.profile, and settings.xml.profile are all active. Also notice that we can see the source of each profile (profiles.xml, pomW, or settings.xml).

Console output from 'mvn help:active-profiles'

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'help'.
[INFO] ------------------------------------------------------------------------
[INFO] Building aproject
[INFO]    task-segment: [help:active-profiles] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [help:active-profiles]
[INFO] 
Active Profiles for Project 'com.maventest:aproject:jar:1.0-SNAPSHOT': 

The following profiles are active:

 - profiles.xml.profile (source: profiles.xml)
 - pom.xml.profile (source: pom)
 - settings.xml.profile (source: settings.xml)



[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Sun Feb 17 00:09:12 PST 2008
[INFO] Final Memory: 2M/5M
[INFO] ------------------------------------------------------------------------

If we perform a 'mvn help:effective-pom' on the 'aproject' project, we can see that the 'settings.xml.property', 'profiles.xml.property', and 'pom.xml.property' values are all available since all three of the profiles that we created are active. These values are located at the bottom of the console output.

Console output from 'mvn help:effective-pom'

[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'help'.
[INFO] ------------------------------------------------------------------------
[INFO] Building aproject
[INFO]    task-segment: [help:effective-pom] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [help:effective-pom]
[INFO] 
************************************************************************************
Effective POM for project 'com.maventest:aproject:jar:1.0-SNAPSHOT'
************************************************************************************
<?xml version="1.0"?><project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.maventest</groupId>
  <artifactId>aproject</artifactId>
  <name>aproject</name>
  <version>1.0-SNAPSHOT</version>
  <url>http://maven.apache.org</url>
  <build>
    <sourceDirectory>C:\dev\workspace\aproject\src\main\java</sourceDirectory>
    <scriptSourceDirectory>src/main/scripts</scriptSourceDirectory>
    <testSourceDirectory>C:\dev\workspace\aproject\src\test\java</testSourceDirectory>
    <outputDirectory>C:\dev\workspace\aproject\target\classes</outputDirectory>
    <testOutputDirectory>C:\dev\workspace\aproject\target\test-classes</testOutputDirectory>
    <resources>
      <resource>
        <directory>C:\dev\workspace\aproject\src\main\resources</directory>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>C:\dev\workspace\aproject\src\test\resources</directory>
      </testResource>
    </testResources>
    <directory>C:\dev\workspace\aproject\target</directory>
    <finalName>aproject-1.0-SNAPSHOT</finalName>
    <plugins>
      <plugin>
        <artifactId>maven-help-plugin</artifactId>
        <version>2.0.2</version>
      </plugin>
    </plugins>
  </build>
  <profiles>
    <profile>
      <id>pom.xml.profile</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <properties>
        <pom.xml.property>pom xml property</pom.xml.property>
      </properties>
    </profile>
  </profiles>
  <repositories>
    <repository>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Repository Switchboard</name>
      <url>http://repo1.maven.org/maven2</url>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
      <id>central</id>
      <name>Maven Plugin Repository</name>
      <url>http://repo1.maven.org/maven2</url>
    </pluginRepository>
  </pluginRepositories>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <reporting>
    <outputDirectory>target/site</outputDirectory>
  </reporting>
  <properties>
    <settings.xml.property>settings xml property</settings.xml.property>
    <profiles.xml.property>profiles xml property</profiles.xml.property>
    <pom.xml.property>pom xml property</pom.xml.property>
  </properties>
</project>
************************************************************************************


[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Sun Feb 17 00:09:59 PST 2008
[INFO] Final Memory: 2M/6M
[INFO] ------------------------------------------------------------------------
Page: < 1 2