Dev/maven

From CubeiaWiki

Jump to: navigation, search

Contents

Firebase and Maven

 NB: From the release of Firebase 1.8.0, the group id of the Firebase archetypes have changed from "com.cubeia.tools" 
 to "com.cubeia.firebase.tools" and the archetype version 1.8.0 matches the Firebase version 1.8.0.

Requirements

This quick start assumes a recent Linux System with Java 1.6 or higher installed. You will also need Maven 2.2.1 or higher installed.

Adding the Cubeia Repository

In order to use the Cubeia Firebase artifacts and archetypes you need to add the Cubeia Nexus maven repository to your maven settings.

<repository>
  <id>cubeia-nexus</id>
  <url>http://m2.cubeia.com/nexus/content/groups/public</url>
  <releases>
    <enabled>true</enabled>
  </releases>
  <snapshots>
    <enabled>true</enabled>
  </snapshots>
</repository>

Creating New Projects

Firebase comes with 4 different archetypes that can be used to create new projects. These are:

  • "firebase-game-archetype" - This creates a maven project for a Game Archive (GAR).
  • "firebase-service-archetype" - This creates a maven project for a Service Archive (SAR).
  • "firebase-tournament-archetype" - This creates a maven project for a Tournament Archive (TAR).
  • "firebase-flex-archetype" - A flex client archetype (SWF).

All the above archetypes are in the "com.cubeia.firebase.tools" group, the current version is 1.9, and you will probably need to point maven to the right repository http://m2.cubeia.com/nexus/content/groups/public.

So to create a new game project, for example, you can execute the following.

mvn archetype:generate \
      -DarchetypeGroupId=com.cubeia.firebase.tools \
      -DarchetypeArtifactId=firebase-game-archetype \ 
      -DarchetypeVersion=1.9 \
      -DarchetypeRepository=http://m2.cubeia.com/nexus/content/groups/public

The generation will ask you for some of the following properties:

  • "groupId" - This is the maven build group id of the new artifact.
  • "artifactId" - The maven build artifact id.
  • "version" - Maven build version, defaults to 1.0-SNAPSHOT
  • "package" - Package for Java or Flex builds
  • "gameId" - The ID of the server game, asked for by the Flex and the Game archetypes

Packaging

If the project is created using an archetype as above, packaging is already configured. Otherwise, you need to first add a build plugin to you POM file. The current version is 1.10

<build>
  <plugins>
    <plugin>
      <groupId>com.cubeia.tools</groupId>
      <artifactId>archive-plugin</artifactId>
      <version>1.10</version>
      <extensions>true</extensions>
    </plugin>
  </plugins>
</build>

Firebase comes with 4 different packaging types:

  • "firebase-gar" - Firebase Game Archive
  • "firebase-sar" - Firebase Service Archive
  • "firebase-tar" - Firebase Tournament Archive
  • "firebase-uar" - Fireabse Unified Archive

Given this, a complete POM for a game ("firebase-gar") may look like this:

<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.my-company.test</groupId>
  <artifactId>funkyGame</artifactId>
  <packaging>firebase-gar</packaging>
  <name>Funky Game</name>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>com.cubeia.firebase</groupId>
      <artifactId>firebase-api</artifactId>
      <version>1.9.0-CE</version>
      <scope>provided</scope>
    </dependency>	
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.14</version>
    </dependency>
  </dependencies>
  
  <build>
    <plugins>
      <plugin>
        <groupId>com.cubeia.tools</groupId>
        <artifactId>archive-plugin</artifactId>
        <version>1.8.0-CE</version>
        <extensions>true</extensions>
      </plugin>
    </plugins>
  </build>
</project>

Running Firebase

If you're standing with a command line within a Firebase GAR, SAR, TAR och UAR project you can run Firebase via the command line. First add the following build plugin:

<plugin>
  <groupId>com.cubeia.tools</groupId>
  <artifactId>firebase-maven-plugin</artifactId>
  <version>1.9.0-CE</version>
</plugin>

The run you module with this command:

mvn clean package firebase:run

By default dependencies of Firebase archives with scope provided will be included in the Firebase instance. Only direct dependencies are included. You can turn this off by adding <includeProvidedArchives>false</includeProvidedArchives> to the configuration section.

You can of course ommit the "clean package" from the command line above, but "package" needs to be run at least once before "firebase:run" is called.

Full plugin configuration with default values

<plugin>
  <groupId>com.cubeia.tools</groupId>
  <artifactId>firebase-maven-plugin</artifactId>
  <version>1.9.0-CE</version>
  <configuration>
    <!-- enable copy of overlay files -->
    <overlaysEnabled>true</overlaysEnabled>

    <!-- copy overlay files from this directory to the firebase root -->
    <overlaySourceDirectory>${basedir}/src/test/resources/firebase</overlaySourceDirectory>

    <!-- included Firebase archives with scope provided -->
    <includeProvidedArchives>true</includeProvidedArchives>
    
    <!-- delete temp firebase instance on exit, set to false for faster startup -->
    <deleteOnExit>true</deleteOnExit>
  </configuration>
</plugin>

Running Firebase With A Game And Multiple Services

A common use case is that you will not only have your game deployed, but also any number of services. The services typically provide wrapper implementation towards your external systems (user database, wallet etc). It is also common that you want to provide local mocked versions of these services to facilitate easier starting and testing of the game server locally for developers.

Games and service archives that are declared as dependencies but with scope=provided will be copied to the /game/deploy folder of the Firebase instance that will be started, i.e. they will be deployed outside and in parallel to the current archive.

Below are some snippets from a pom.xml that will deploy a mock wallet service in parallel to the current archive (example is taken from our Poker):

    <!-- The game will be included in the unified archive -->
    <dependency>
        <groupId>com.cubeia.games</groupId>
        <artifactId>poker-game</artifactId>
        <type>firebase-gar</type>
    </dependency>

    <!-- Mock Wallet service is provided and will be deployed in parallel -->
    <dependency>
        <groupId>com.cubeia.network.wallet.firebase</groupId>
        <artifactId>mock-wallet-service</artifactId>
        <version>1.2.3</version>
        <type>firebase-sar</type>
        <scope>provided</scope>
    </dependency>
Personal tools