Usage

Plugin configuration

You should specify the version in your project's plugin configuration:

<project>
  ...
  <build>
    <!-- To use the plugin goals, add the following in your POM or parent POM -->
    <plugins>
      <plugin>
        <groupId>com.github.fracpete</groupId>
        <artifactId>debian-maven-plugin</artifactId>
        <version>1.0.24</version>
        <configuration>
          <!--
          <packageName>my-package</packageName>
          <packageVersion>1.0.0</packageVersion>
          ...
          -->
        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

The plugin accepts the following configuration parameters (most of them have reasonable default values):

POM setting Command line argument Description Data type Default value
skip Whether to skip the execution. To be used in multi-module projects, with the top-level module setting it to true and the sub-modules to false. boolean false
packageName deb.package.name Package name String  ${project.artifactId}
packageVersion deb.package.version Package version String  ${project.version}
packageRevision deb.package.revision Package revision String 1
packagePriority deb.package.priority Installation priority String optional
packageSection deb.package.section Repository section String contrib/utils
packageTitle deb.package.title Short package description String  ${project.name}
packageDescription deb.package.description Extended package description String  ${project.description}
snapshotRevisionFile deb.package.snapshotRevFile When building snapshot packages, append the modification time of this file to the version number. File The default is to use the system time.
packageDependencies Dependencies to other packages String[]
projectUrl deb.project.url Project website String  ${project.organization.url}
projectOrganization deb.project.organization Organization for Debian control file String  ${project.organization.name}
maintainerName deb.maintainer.name Package maintainer's name String  ${project.developers[0].name}
maintainerEmail deb.maintainer.email Package maintainer's email address String  ${project.developers[0].email}
includeArtifacts Artifacts to be included, identified by their filenames. String[] The project artifact and its dependencies.
excludeArtifacts Artifacts to be excluded (takes precedence over includeArtifacts). String[]
excludeArtifactsRegExp Regular expression to match against artifacts to be excluded (takes precedence over includeArtifacts). Applies the expressions to "groupId:artifactId:classifier" String[]
excludeAllArtifacts Exclude all regular artifacts (attached artifacts are not affected) Boolean false
excludeAllDependencies Exclude all dependencies Boolean false
includeAttachedArtifacts Include all attached artifacts. Boolean true
includeScope Scopes to be included (comma-separated list), empty string includes all scopes. String "compile".
excludeScope Scopes to be excluded (comma-separated list), empty string does not exclude any scopes. String Empty string.
libDirectory The directory to contain the libraries. Placeholder PKGNAME gets replaced with value of packageName. String /usr/lib/{PKGNAME}
docDirectory The directory to contain the documentation. Placeholder PKGNAME gets replaced with value of packageName. String /usr/share/doc/{PKGNAME}
manDirectory The directory to contain the man pages. Placeholder PKGNAME gets replaced with value of packageName. String /usr/share/man
createSymLinks Whether to create symbolic links for jars without the artifact version. boolean true
createIncludeFiles Whether to create .inc files for the artifacts. boolean true
useDefaultFixPermissions Whether to use default rules for fixing file permissions (setting 755 on scripts in bin and sbin and pre and post scripts in DEBIAN). boolean false
fixPermissions Custom rules for applying permissions to files, using nested fixPermission with include regular expression (eg .*myscript.*) and permissions POSIX permissions string (eg rwxr-xr-x). FixPermission[] false
useDefaultCopyResources Whether to use default rules for copy resource files (from src/deb/resources to target/deb). boolean false
copyResources Custom rules for copying resources, using nested copyResource with include regular expression (eg .*myscript.*) and source and target strings (dir or file). CopyResource[] false
fileFiltering If enabled, allows replacing of variables ("${...}") in files that match the include (default: .*) but not the exclude (default: .*\.(jpg|jpeg|png|svg|zip|jar|pdf)) pattern. FileFiltering disabled
compressionType The type of compression to use (sysdefault, gzip, xz, etc.). "sysdefault" uses the default compression used by the underlying build system. String gzip
attach Whether to attach the built package to the project boolean false
repository deb.repository.location Location of the Debian repository File
codenames The codenames of the distribution branches (e.g., lenny, natty, etc.) String experimental
repreproConfigurotionDir deb.reprepro.config Reprepro configuration directory File
skipDeployMissing deb.deploy.skipMissing Skip package deployment if the package does not exist Boolean true

Skipping execution

The plugin execution is skipped automatically if the operating system is not linux. The plugin execution can be skipped explicitly by providing the system property skipDeb, and it is forced to run regardless the operating system if runDeb is provided. Example:

mvn -DskipDeb

Multi-module projects

The top-level module in multi-module projects usually only defines plugins, properties, etc, but does not actually contain any code that requires packaging. In order to avoid execution in the top-level module, you can use the skip parameter set to true:

<build>
  <plugins>
    ...

    <plugin>
      <groupId>com.github.fracpete</groupId>
      <artifactId>debian-maven-plugin</artifactId>
      <configuration>
        <skip>true</skip>
      </configuration>
    </plugin>
    ...
  </plugins>
</build>

And in the sub-modules, you set this flag to false:

<build>
  <plugins>
    ...

    <plugin>
      <groupId>com.github.fracpete</groupId>
      <artifactId>debian-maven-plugin</artifactId>
      ...
      <configuration>
        <skip>false</skip>
        ...
      </configuration>
    </plugin>
    ...
  </plugins>
</build>

Adding package content

Adding JARs (and other attached artifacts and dependencies)

By default, the project artifact, its dependencies, and attached artifacts are packaged. The project artifact and its dependencies can be excluded from the package by setting excludeAllArtifacts to true. The parameter excludeAllDependencies does the same, but only for dependencies. The inclusion of attached artifacts is governed by includeAttachedArtifacts. If includeArtifacts is provided, only those listed artifacts are included. The artifacts in excludeArtifacts (supplied in via nested <param></param> tags) are excluded from the Debian package. You can also supply regular expressions to exclude artifacts using excludeArtifactsRegExp (the actual regular expressions are supplied in nested <param></param> tags). Artifacts will be accompanied by a symbolic link, which enables reference without the version number.

For the project artifact and each of its dependencies, a file is created which lists all dependencies of the artifact. The name of this file is the artifact filename with its extension replaced by .inc. This is particularly useful for setting the classpath, e.g. from a shell script.

Adding man pages

The plugin searches for man page source files in the directory src/deb/man. The files are automatically compiled, using groff. The source files must be named pagename.N, where N is the section number. The compiled man pages are gzip'ed and included in the appropriate place in the deb file. Here are some pointers for help writing man pages:

Adding other files

By default, the plugin only takes care of JARs. However, if you require additional resources to be part of your debian package (eg scripts in /usr/bin), then you can use the useDefaultCopyResources and copyResources parameters to achieve this.

With useDefaultCopyResources set to true, the plugin copies everything below src/deb/resources into the staging directory target/deb.

copyResources allows you to copy other files as well. Each of the nested copyResource tags is comprised of source, target and an optional include tags. Both, source and target can be directories or files. The include tag uses regular expressions for matching files to include in the copy process. If omitted, the match all pattern .* is assumed.

The following example applies the default copy rules and also copies PDF files from the target directory into target/deb/usr/share/doc/my-package to make them available in /usr/share/doc/my-package after installing the package.

<build>
  <plugins>
    ...

    <plugin>
      <groupId>com.github.fracpete</groupId>
      <artifactId>debian-maven-plugin</artifactId>
      <configuration>
        <packageName>my-package</packageName>
        <packageVersion>1.0.0</packageVersion>
        <useDefaultCopyResources>true</useDefaultCopyResources>
        <copyResources>
          <copyResource>
            <source>target</source>
            <target>target/deb/usr/share/doc/my-package</target>
            <include>.*\.pdf</include>
          </copyResource>
        </copyResources>
      </configuration>
    </plugin>
    ...
  </plugins>
</build>

Unfortunately, the copying does not retain Unix file permissions, meaning that all executable files lose their execution permission after copying. But you can use the useDefaultFixPermissions and fixPermissions parameters to counter this.

When useDefaultFixPermissions is set to true, then the plugin ensures that all scripts in the bin and sbin directories and the DEBIAN/pre and DEBIAN/post scripts are executable (using rwxr-xr-x).

fixPermissions allows you to change the permissions of other files and directories. Each of the nested fixPermission tags consists of the include regular expression to match against the full filename and permissions containing the ugo (user, group, other) permissions.

Here is an example that applies the default permission fixes and also ensures that the myscript script is executable as well:

<build>
  <plugins>
    ...

    <plugin>
      <groupId>com.github.fracpete</groupId>
      <artifactId>debian-maven-plugin</artifactId>
      <configuration>
        <packageName>my-package</packageName>
        <packageVersion>1.0.0</packageVersion>
        <useDefaultFixPermissions>true</useDefaultFixPermissions>
        <fixPermissions>
          <fixPermission>
            <include>.*myscript.*</include>
            <permissions>rwxr-xr-x</permissions>
          </fixPermission>
        </fixPermissions>
      </configuration>
    </plugin>
    ...
  </plugins>
</build>

Filtering files

By default, resource files are just copied across as is. However, in order to make start-up scripts more general, you can place variables (${varname}) in them and turn file filtering on in your configuration.

In terms of what variables are supported, there are two types: The first type being POM related ones, that start with project. like project.name or project.version. Sub-properties from properties in the POM that allow multiple values, like licenses can access these via [index], with the index being 0-based. The second type are ones specific to this plugin. Here is a list of supported variables:

packageName
packageTitle
packagePriority
packageSection
packageDescription
packageArchitecture
packageRevision

Considering the following configuration for file filtering:

...

<licenses>
  <license>
    <name>GNU General Public License 3</name>
    <url>http://www.gnu.org/licenses/gpl-3.0.txt</url>
  </license>
  <license>
    <name>Apache 2.0</name>
    <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
  </license>
</licenses>

...

<build>
  <plugins>
    ...

    <plugin>
      <groupId>com.github.fracpete</groupId>
      <artifactId>debian-maven-plugin</artifactId>
      <configuration>
        <packageName>my-package</packageName>
        <packageVersion>1.0.0</packageVersion>
        <fileFiltering>
          <enabled>true</enabled>
          <include>.*</include>
          <excluded>.*\.(jpg|jpeg|png|svg|zip|jar|pdf)</excluded>
        </fileFiltering>
      </configuration>
    </plugin>
    ...
  </plugins>
</build>

When applied to the following snippet of a bash script (the blank between $ and { was required for display purposes):

...
# Licenses
# - $ {project.licenses[0].name}
# - $ {project.licenses[1].name}

CLASSPATH_DIR=/usr/lib/${packageName}
...

Will yield this output:

# Licenses
# - GNU General Public License 3
# - Apache 2.0

CLASSPATH_DIR=/usr/lib/my-package

Deploying

The plugin can use reprepro to deploy the Debian package to a local reprepro repository. The plugin assumes an existing reprepro repository and configuration, and requires pointers to their locations. The plugin uses the following parameters:

  • repository (path to the repository; eg: /path/to/repo)
  • repreproConfigurationDir (the reprepro configuration directory)
  • repositoryBranch (optional)
  • skipDeployMissing (optional)

Note: when the package version has the substring -SNAPSHOT, it is replaced by the modification time of the file pom.xml. This way, each change of the POM causes an increase of the version number, which is useful as reprepro does not allow you to deploy an update with the same version number.

Examples

Examples can be found in the following repository:

https://github.com/fracpete/debian-maven-plugin-examples