Configure default and alternative executions in maven pom using profiles

By neokrates, written on June 2, 2010

howto

  • Join date: 11-30-99
  • Posts: 224
View Counter:
  • 552 views
Rate it
Ad
Poll
  • What build management tool does your project or firm use?

    View Results

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext

Maybe you develop an alternative build chain path. You want all to function default way. But, with one switch you want to be able to change the build chain logic. All steps or just some.

That can be done with maven’s profiles inside the pom. Here is a basic pom, which will execute one build step per default, and another if you give the particular profile name:

 
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>my.group</groupId>
  <artifactId>my.id</artifactId>
  <name>my.name</name>
  <version>1.1-SNAPSHOT</version>

  <profiles>
  <profile>
      <id>DefaultProfile</id>
      <activation><activeByDefault>true</activeByDefault></activation>
      <build>
      <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            <id>DEFAULT-profile</id>
            <phase>initialize</phase>
            <configuration>
              <tasks>
                <echo> --- Execute default configuration with DEFAULT profile --- </echo>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>

        <dependencies>
          <dependency>
            <groupId>org.codehaus.gant</groupId>
            <artifactId>gant_groovy1.7</artifactId>
            <version>1.9.2</version>
          </dependency>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>1.7.0</version>
          </dependency>
        </dependencies>
      </plugin>
</plugins>
</build>
</profile>
    
    <profile>
      <id>AltProfile</id>
      <build>
      <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.3</version>
        <executions>
          <execution>
            <id>ALT-profile</id>
            <phase>initialize</phase>
            <configuration>
              <tasks>
                <echo> *** Execute alternative configuration with ALT Profile *** </echo>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>

        <dependencies>
          <dependency>
            <groupId>org.codehaus.gant</groupId>
            <artifactId>gant_groovy1.7</artifactId>
            <version>1.9.2</version>
          </dependency>
          <dependency>
            <groupId>org.codehaus.groovy</groupId>
            <artifactId>groovy-all</artifactId>
            <version>1.7.0</version>
          </dependency>
        </dependencies>
      </plugin>

      
      </plugins>
     </build>
   </profile>
    
  </profiles>
 
  
  
</project>

No profiles, means default is used:

> mvn clean install

...

[INFO] [antrun:run {execution: DEFAULT-profile}]
[INFO] Executing tasks
     [echo] --- Execute default configuration with DEFAULT profile ---
[INFO] Executed tasks

...

Alternative profile is invoked, default will be disabled:

> mvn clean install -PAltProfile

...

[INFO] [antrun:run {execution: ALT-profile}]
[INFO] Executing tasks
     [echo] *** Execute alternative configuration with ALT Profile ***
[INFO] Executed tasks

...

Be Sociable, Share!
 
Does that help to solve your problem?
VN:F [1.8.5_1061]
Rating: +6 (from 6 votes)
6 votes 'YES'  0 votes 'NO'

LEARN MORE (amazon bookstore)

TAGS

SOCIAL
Be Sociable, Share!

INCOMING SEARCH TERMS


Leave a Reply