Archive

Archive for October, 2012

Using the Maven Antrun Plugin to output the version number to a text file

<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>write-property</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  
  <properties>
    <version>1.0.1</version>
    <maven.build.timestamp.format>yyyyMMdd-HHmmss</maven.build.timestamp.format>
    <current.build.date>${build.timestamp}</current.build.date>
  </properties>
  
  <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>
                <propertyfile file="version.properties" comment="Version information">
                  <entry key="version" value="${version}" />
                  <entry key="current.build.date" value="${current.build.date}" />
                </propertyfile>
              </tasks>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
mvn validate

The Maven Plugin creates the following version.properties file:

#Version information
#Tue, 23 Oct 2012 13:09:23 +0200

version=1.0.1
current.build.date=20121023-130922
Advertisements

Copy a directory with Maven Resources Plugin

October 17, 2012 2 comments
<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>copy-resources</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-resources-plugin</artifactId>
				<version>2.6</version>
				<executions>
					<execution>
						<id>copy-resources</id>
						<phase>validate</phase>
						<goals>
							<goal>copy-resources</goal>
						</goals>
						<configuration>
							<outputDirectory>${project.basedir}\outputdir</outputDirectory>
							<resources>
								<resource>
									<directory>${project.basedir}\inputdir</directory>
									<filtering>false</filtering>
								</resource>
							</resources>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>
mvn validate

The Plugin has an optional parameter “includeEmptyDirs” with a default value “false”. Add the parameter to the plugin configuration to copy any empty directories included in the Resources.

...
<includeEmptyDirs>true</includeEmptyDirs>
...

For more informations have a look at the docu here.

Execute specific Maven goal using profiles

October 17, 2012 1 comment
<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.

Clean directories with Maven

<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>clean-directory</artifactId>
	<packaging>pom</packaging>
	<version>0.0.1-SNAPSHOT</version>

	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-clean-plugin</artifactId>
				<version>2.5</version>
				<configuration>
					<filesets>
						<fileset>
							<directory>c:/test1</directory>
						</fileset>
						<fileset>
							<directory>c:/test2</directory>
						</fileset>
					</filesets>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>
mvn clean

Echo the value of a Maven property

<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>echo-property</artifactId>
	<packaging>pom</packaging>
	<version>0.0.1-SNAPSHOT</version>

	<properties>
		<testproperty>This is a test property</testproperty>
	</properties>

	<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>Displaying value of 'testproperty' property</echo>
								<echo>[testproperty]: ${testproperty}</echo>
							</tasks>
						</configuration>
					</execution>
				</executions>
			</plugin>
		</plugins>
	</build>
</project>
mvn validate

Use adb to uninstall an APK from connected device

adb uninstall <package name>

Categories: Android, Development