Home > Build-Management, Software Engineering > Execute specific Maven goal using profiles

Execute specific Maven goal using profiles

<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>com.test</groupId>
	<artifactId>specific-goal</artifactId>
	<version>0.0.1-SNAPSHOT</version>	
	<packaging>pom</packaging>
	
	<profiles>
		<profile>
			<id>profile-one</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-antrun-plugin</artifactId>
						<version>1.4</version>
						<executions>
							<execution>
								<phase>validate</phase>
								<goals>
									<goal>run</goal>
								</goals>
								<configuration>
									<tasks>
										<echo>goal one</echo>
									</tasks>
								</configuration>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
		<profile>
			<id>profile-two</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-antrun-plugin</artifactId>
						<version>1.4</version>
						<executions>
							<execution>
								<phase>validate</phase>
								<goals>
									<goal>run</goal>
								</goals>
								<configuration>
									<tasks>
										<echo>goal two</echo>
									</tasks>
								</configuration>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>
</project>

To call the above profiles, run the following command:

mvn validate -Pprofile-one

or

mvn validate -Pprofile-two

If you call validate without a profile no goal will be executed:

mvn validate

Profiles can also be active by default using a configuration like the following:

<profiles>
  <profile>
    <id>profile-one</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
    ...
  </profile>
</profiles>

For more informations have a look at the Build Lifecycle and Profiles.

Advertisements
  1. June 19, 2013 at 05:04

    I was studying some of your articles on this website and I conceive this web site is rattling informative ! Keep on posting .

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s