How to customize maven using profile

You can customize your maven build by creating a maven profile. The code is given below.


<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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>mavenprofile1</groupId>
	<artifactId>mavenprofile1</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>jar</packaging>

	<name>mavenprofile1</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
	</properties>

	<dependencies>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>3.8.1</version>
			<scope>test</scope>
		</dependency>
	</dependencies>

	<build>
		<plugins>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>exec-maven-plugin</artifactId>
				<version>1.1.1</version>
				<executions>
					<execution>
						<phase>install</phase>
						<goals>
							<goal>java</goal>
						</goals>
						<configuration>
							<mainClass>mavenprofile1.mavenprofile1.Test</mainClass>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>

	<profiles>
		<profile>
			<id>dev</id>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
			<build>
				<plugins>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-jar-plugin</artifactId>
						<version>2.3</version>
						<configuration>
							<excludes>
								<exclude>**/app-prod.properties</exclude>
								<exclude>**/app-uat.properties</exclude>
							</excludes>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
		<profile>
			<id>prod</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-jar-plugin</artifactId>
						<version>2.3</version>
						<configuration>
							<excludes>
								<exclude>**/app-uat.properties</exclude>
								<exclude>**/app-dev.properties</exclude>
							</excludes>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
		<profile>
			<id>uat</id>
			<build>
				<plugins>
					<plugin>
						<groupId>org.apache.maven.plugins</groupId>
						<artifactId>maven-jar-plugin</artifactId>
						<version>2.3</version>
						<configuration>
							<excludes>
								<exclude>**/app-prod.properties</exclude>
								<exclude>**/app-dev.properties</exclude>
							</excludes>
							<archive>
								<manifest>
									<addClasspath>true</addClasspath>
									<mainClass>mavenprofile1.mavenprofile1.Test</mainClass>
								</manifest>
							</archive>
						</configuration>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>


</project>


 

Advertisements

« Older entries