Page tree

 

Shows how to use the Apptools Maven Plugin in a separate POM project.

If you need a version controlled specification of a set of app to be deployed to defined environments, a separate POM is the way to go.

In the POM file you will list the artifacts with their versions and the environments you want to deploy to.

The following shows a configuration where the different target environments are configured with the POM file. This makes the different environments immediately accessible to users of the project.

Unfortunately this configuration lacks flexibility in case you administrate more than one project. In this case you may want to check the alternative configuration we show at the end of this tutorial.

Basic Configuration

Simply add the configuration to the POM file of your project.

pluginManagement in pom.xml
<build>
  ...
  <pluginManagement>
    <plugins>
      ...
      <plugin>
        <groupId>de.smartics.maven.plugin</groupId>
        <artifactId>apptools-maven-plugin</artifactId>
        <version>0.12.0</version>
      </plugin>
    </plugins>
  </pluginManagement>
  ...
</build>

You may specify default includes and excludes or impose a processing order with order. This will catch the default behavior and will make the deployment specification easier to use since less parameters need to be set on the command line.

Configure Apps

With this approach we intend to define a set of artifacts by their version. The POM is typically stored in a version control systems. To download dependencies the artifacts are specified explicitly.

Since version 0.8.0 the artifacts can be defined within the configuration of the plugin.

pluginManagement in pom.xml
<build>
  ...
  <pluginManagement>
    <plugins>
      ...
      <plugin>
        <groupId>de.smartics.maven.plugin</groupId>
        <artifactId>apptools-maven-plugin</artifactId>
        <version>0.12.0</version>
        <configuration>
          <artifacts>
            <gav>com.example.project:my-artifact-one:obr:${version.my-artifact-one}</gav>
            ...
            <gav>com.example.project:my-artifact-last:${version.my-artifact-last}</gav>
          </artifacts>
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
  ...
</build>

Prior versions needed to have the artifacts source folder filled by the Maven Dependency Plugin like this:

plugins in build of pom.xml
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>${version.maven-dependency-plugin}</version>
        <executions>
          <execution>
            <id>copy</id>
            <phase>generate-resources</phase>
            <goals>
              <goal>copy</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <artifactItems>
            <artifactItem>
              <groupId>com.example.project</groupId>
              <artifactId>my-artifact-one</artifactId>
              <version>${version.my-artifact-one}</version>
              <type>obr</type>
            </artifactItem>
            ...
            <artifactItem>
              <groupId>com.example.project</groupId>
              <artifactId>my-artifact-last</artifactId>
              <version>${version.my-artifact-last}</version>
              <type>jar</type>
            </artifactItem>
          </artifactItems>
          <outputDirectory>${project.build.directory}/apps</outputDirectory>
          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>true</overWriteSnapshots>
        </configuration>
      </plugin>

Then specify the versions as properties in profiles. This way the declaration of the versions is more concise and you may have different sets of versions, e.g. for releases and snapshots.

profiles in pom.xml
  <profile>
    <id>snapshots</id>
    <properties>
      <version.my-artifact-one>1.6.2-SNAPSHOT</version.my-artifact-one>
      ...
      <version.my-artifact-last>1.3.0-SNAPSHOT</version.my-artifact-last>
    </properties>
    <build>
      <pluginManagement>
        <plugins>
          <plugin>
            <groupId>de.smartics.maven.plugin</groupId>
            <artifactId>apptools-maven-plugin</artifactId>
            <configuration>
              <requireReleases>false</requireReleases>
            </configuration>
          </plugin>
        </plugins>
      </pluginManagement>
    </build>
  </profile>
  <profile>
    <id>releases</id>
    <properties>
      <version.my-artifact-one>1.6.0</version.my-artifact-one>
      ...
      <version.my-artifact-last>1.2.0</version.my-artifact-last>
    </properties>
    <build>
      <pluginManagement>
        <plugins>
          <plugin>
            <groupId>de.smartics.maven.plugin</groupId>
            <artifactId>apptools-maven-plugin</artifactId>
            <configuration>
              <requireReleases>true</requireReleases>
            </configuration>
          </plugin>
        </plugins>
      </pluginManagement>
    </build>
  </profile>
</profiles>

Configure Servers

We recommend the practice of configuring different environments in build profiles as part of the Maven POM file.

Per convention we use all-uppercase identifiers for profiles that contain environments. The Apptools Maven Plugin is able to recognize environment profiles with this convention.

This is a short tutorial on how environment configurations can be stored with build profiles.

The following shows a configuration where the different target environments are configured with the POM file. This makes the different environments immediately accessible to users of the project.

Unfortunately this configuration lacks flexibility in case you administrate more than one project. In this case you may want to check the alternative configuration we show at the end of this document.

Configure local Server

Add build profiles to configure the Confluence servers you want to deploy to.

The following shows the deployment to the locally started Confluence on a developer machine (with default password and user admin).

profile in pom.xml with predentials
<profiles>
  <profile>
    <id>LOCAL</id>
    <activation>
      <activeByDefault />
    </activation>
    <build>
      <pluginManagement>
        <plugins>
          <plugin>
            <groupId>de.smartics.maven.plugin</groupId>
            <artifactId>apptools-maven-plugin</artifactId>
            <configuration>
              <username>admin</username>
              <password>admin</password>
              <serverUrl>http://localhost:1990/confluence</serverUrl>
            </configuration>
          </plugin>
        </plugins>
      </pluginManagement>
    </build>
  </profile>
  ...
</profiles>

Deploy the OSGi Bundle Repository (OBR) artifact to the local server by specifying the build profile.

mvn apptools:deploy -PLOCAL

Configure remote Server

In case you want to deploy to a remote test server, add a build profile.

profile in pom.xml without credentials
    <profile>
      <id>TEST</id>
      <build>
        <pluginManagement>
          <plugins>
            <plugin>
              <groupId>de.smartics.maven.plugin</groupId>
              <artifactId>apptools-maven-plugin</artifactId>
              <configuration>
                <serverId>confluence-test</serverId>
                <serverUrl>${my.server.url.TEST}</serverUrl>
              </configuration>
            </plugin>
          </plugins>
        </pluginManagement>
      </build>
    </profile>

Provide the credentials and the uniform resource locator (URL) to access the TEST server in your Maven Settings file.

~/.m2/settings.xml
<settings>
  ...
  <servers>
    ...
    <server>
      <id>confluence-test</id>
      <username>jane.doe</username>
      <password>{HllO1A....}</password>
    </server>
  </servers>
...
  <profiles>
    <profile>
        <my.server.url.TEST>https://www.mycorp.example.com/confluence</my.server.url.TEST>
      </properties>
    </profile>
    ...
  </profiles>
</settings>

Since the POM is bundled with your artifact, the URL to the test systems is not be revealed, if specified as a property provided with the settings file. This way it is also easier to change the URL for all your projects without the need to update each POM individually.

Deploy to remote Server

Deploy the OBR artifact to the remote test server by specifying the build profile.

mvn apptools:deploy -PTEST

Alternative Configuration

This configuration has advantages when environments need to be added or removed.

With the configuration explained above you would need to alter the POM file of every project. You can keep this configuration effort local to the settings file if you use the following configuration in your POMs:

pom.xml
<build>
  ...
  <pluginManagement>
    <plugins>
      ...
      <plugin>
        <groupId>de.smartics.maven.plugin</groupId>
        <artifactId>apptools-maven-plugin</artifactId>
        <version>0.12.0</version>
        <configuration>
          ... <!-- same as above, plus: -->

          <serverId>${my-project.apptools.remote.server.id}</serverId>
          <serverUrl>${my-project.apptools.remote.server.url}</serverUrl>
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
  ...
</build>

Then in your settings.xml add the following as a profile element for each of your environments.

settings.xml
<settings>
  ...
  <servers>
    <server>
      <id>my-server-id</id>
      <username>janedoe</username>
      <password>{swldfcm .... ssdfsdaf323=}</password>
    </server>
  </servers>

  ...

  <profiles>
    <profile>
      <id>MY_ENV_ID</id>
      <properties>
        <projectdoc.apptools.remote.server.id>my-server-id</projectdoc.apptools.remote.server.id>
        <projectdoc.apptools.remote.server.url>https://myserver/confluence</projectdoc.apptools.remote.server.url>
      </properties>
    </profile>
  </profiles>
</settings>

Resources

Usage
Information on use scenarios of the Apptools Maven Plugin.
Use in App Project
Shows how to add the Apptools Maven Plugin to your Confluence add-on project.