Skip to content

Deb Plugin

Danny Thomas edited this page Dec 13, 2020 · 10 revisions

This plugin provides Gradle-based assembly of DEB packages, typically for Linux distributions derived from Debian, e.g. Ubuntu. It leverages JDeb Java library.

Basic Usage

buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'com.netflix.nebula:gradle-ospackage-plugin:8.4.1'
    }
}

apply plugin: 'nebula.deb'

task fooDeb(type: Deb) {
    release '1'
}

Task Usage

The DEB plugin provides a Task based on a standard copy task, similar to the Zip and Tar tasks. The power comes from specifying "from" and "into" calls, read more in the Copying files section of the Gradle documentation. On top of the standard available methods, there are some additional values that be set, which are specific to DEBs. Quite of them have defaults which fall back to fields on the project.

Value Description
packageName Default to project.name
release DEB Release
version Version field, defaults to project.version
epoch Epoch, defaults to 0
user Default user to permission files to
permissionGroup Default group to permission files to, "group" is used by Gradle for the display of tasks
packageGroup
buildHost
summary
packageDescription Defaults to project.description
packager
distribution
vendor
url
signingKeyId
signingKeyPassphrase
signingKeyRingFile
sourcePackage
provides
createDirectoryEntry [Boolean]
uid Default uid of files
gid Default gid of files
arch Architecture, defaults ot "all". E.g. "amd64", "all"
maintainer Defaults to packager
uploaders Defaults to packager
priority
multiArch Configure multi-arch behavior: NONE (default), SAME, FOREIGN, ALLOWED (see: https://wiki.ubuntu.com/MultiarchSpec )
conflicts
recommends
suggests
enhances
preDepends
breaks
replaces

Symbolic Links

Symbolic links are specified via the links method, where the permissions umask is optional:

link(String symLinkPath, String targetPath, int permissions)

Requires

Required packages are specified via the required method:

requires(String packageName)

or

requires(String packageName, String version)

or

requires(String packageName, String version, int flag) 

For information about possible flags, see Dependency.groovy.

Alternative Dependencies

As of v3.6.0, alternative dependencies are supported through or:

requires(String packageName, String version, int flag).or(String packageName, String version, int flag)

Other Relationships

Debian packages support declaration of other relationships. The Deb task supports the following in addition to Requires:

  • conflicts
  • recommends
  • suggests
  • enhances
  • preDepends (configures the Pre-Depends field)
  • breaks
  • replaces

For more information, see the Debian Policy Manual section on relationships. Syntax is identical to requires

Scripts

To provide the scripts traditionally seen in the spec files, they are provided as Strings or as files. Their corresponding methods can be called multiple times, and the contents will be appended in the order provided.

  • preInstall
  • postInstall
  • preUninstall
  • postUninstall
  • installUtils - Scripts which are prefixed to all the other scripts.
  • configurationFiles - Files to be labeled as configuration files

Complete maintainer scripts can also be provided as files:

  • preInstallFile file('./scripts/my-preinstall-file.sh')
  • postInstallFile
  • preUninstallFile
  • postUninstallFile

Calling a complete file directive and the contents directives above will throw an exception. For example, a build script cannot have both preInstallFile and preInstall.

User-Defined Control Headers

Per the Debian Policy Manual, user-defined headers may be contributed to a package. Use the customField method to add key/val pairs, merge existing maps, or modify the customFields map directly. See example below.

Copy Spec

The following attributes can be used inside from and into closures to complement the Copy Spec.

  • user
  • permissionGroup
  • fileType
  • uid
  • gid

(Above can be set via property syntax, e.g. "user='jryan'", or method syntax, e.g. "user 'jryan'")

Example

    task fooDeb(type: Deb) {
        packageName = 'foo'
        version = '1.2.3'
        release = 1

        configurationFile('/etc/defaults/myapp')
        installUtils file('scripts/deb/utils.sh')
        preInstall file('scripts/deb/preInstall.sh')
        postInstall file('scripts/deb/postInstall.sh')
        preUninstall file('scripts/deb/preUninstall.sh')
        postUninstall file('scripts/deb/postUninstall.sh')

        requires('bar', '2.2')
        requires('baz', '1.0.1')
        requires('qux')

        into '/opt/foo'

        from(jar.outputs.files) {
            into 'lib'
        }
        from(configurations.runtime) {
            into 'lib'
        }
        from('lib') {
            into 'lib'
        }
        from('scripts') {
            into 'bin'
            exclude 'database'
            fileMode 0550
        }
        from('src/main/resources') {
            fileType CONFIG | NOREPLACE
            into 'conf'
        }
        from('home') {
            createDirectoryEntry = true
            fileMode 0500
            into 'home'
        }
        from('endorsed') {
            into '/usr/share/tomcat/endorsed'
        }

        link('/etc/init.d/foo', '/opt/foo/bin/foo.init')

        customField 'Build-Host', 'http://mycihost'
        customField([
            'Commit-ID': 'deadbeef',
            'Owner': 'John Doe <johndoe@sweetdomain.io>'
        ])
        customFields << [
            'Build-Job': 'FooProject'
        ]
    }