UDK extension packages

This page describes what is considered best practice. It was written for Pogamut 3.2.5, but should apply seamlessly to future versions. While this approach could be extended to all pogamut variants, it is currently fully implemented only for UDK.

This article was written by Martin Černý

In most cases your Pogamut-UDK project depends on some extension to the UDK, at least on Gamebots for UDK. It is desirable for your Java project to reflect this dependency and allow to install such extensions upon building the project. To achieve this we introduce the concept of UDK extension packages.

UDK extension package is simply a zip-packaged Maven artifact, that contains files for the extension, such that they may be extracted directly into the UDK folder. Best practices for installing extensions upon build of your project may be found at Gamebots - Maven article.

The benefit of this packaging is that you may declare explicit dependency of your project on a concrete version of GameBots or other extension package and let Maven manage such a dependency for you.

Creating packages

Packages are created as pom-packaged artifacts that employ maven-assembly-plugin to build the zip file. They follow typical maven project directory structure:

/-|
  |-src
    |-main
      |-assembly   //contains the assembly descriptor
      |-udk  //contains the actual UDK files
  |-target   //compilation output
  |-pom.xml

In order to take advantage of all Maven capabilities (filtering, adding version numbers,…), udk resources are copied to target directory before being added to assembly.

Here is an example of a pom.xml for UDK extension for project SpyVsSpy:

 
<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>
    <parent>
        <groupId>cz.cuni.amis</groupId>
        <artifactId>amis-pom</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../AmisPom/pom.xml</relativePath>
    </parent>
 
    <groupId>cz.cuni.amis.pogamut.spyvsspy</groupId>
    <artifactId>spyvsspy-udk</artifactId>
    <version>3.2.5-SNAPSHOT</version>
    <packaging>pom</packaging>
 
    <name>SpyVsSpy UDK package</name>
    <url>http://pogamut.cuni.cz</url>
 
 
    <build>
        <resources> <!-- Declares the UDK resource directory to be copied to output -->
            <resource>
                <directory>${basedir}/src/main/udk</directory>
                <targetPath>${project.build.directory}/udk</targetPath>
            </resource>
        </resources>
        <plugins>
            <!-- The project is pom packaged in order to get rid of JAR output. But we need to 
            explicitly call resources plugin-->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>resources</goal>
                        </goals>
                        <phase>process-resources</phase>
                    </execution>
                </executions>
            </plugin>
 
            <!-- Create the zip package -->           
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <descriptors>
                        <descriptor>${basedir}/src/main/assembly/assembly.xml</descriptor>
                    </descriptors>
                </configuration>
                <executions>
                    <execution>
                        <id>zip</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Note that if you inherit from amis-pom, you need to add empyt files called : skip.default-jar and skip.source-jars, otherwise amis-pom will force the creation of binary and source JARS eventhough this is a POM. Project.

A typical content of /src/main/assembly/assembly.xml follows:

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
  <includeBaseDirectory>false</includeBaseDirectory>
  <formats>
    <format>zip</format>
  </formats>
  <fileSets>
    <fileSet>
      <directory>${project.build.directory}/udk</directory>
	  <outputDirectory>/</outputDirectory>
    </fileSet>  
  </fileSets>
</assembly>