This plugin provides Gradle-based assembly of system packages, typically for RedHat and Debian based distributions, using a canonical Gradle Copy Specs. It's structured as three plugins, which work in concert, and a fourth plugin to pull them all together. Keep reading to see some power examples, follow the links to further pages for the formal documentation. All the plugins are pure-java and don't require any local native binaries.
Gradle requires that plugins be added to the classpath as part of the classpath. For Gradle 2.0+ projects, you can use the plugins
DSL to bring in this plugin:
plugins {
id 'nebula.ospackage' version '3.4.0'
}
For older versions of gradle
buildscript {
repositories { jcenter() }
dependencies {
classpath 'com.netflix.nebula:gradle-ospackage-plugin:3.4.0'
}
}
apply plugin: 'nebula.ospackage'
This plugin provides Gradle-based assembly of RPM packages, typically for Linux distributions derived from RedHat. It leverages Redline Java library.
This plugin provides Gradle-based assembly of DEB packages, typically for Linux distributions derived from Debian, e.g. Ubuntu. It leverages JDeb Java library.
For the scenarios where packages have to be built for both CentOS and Ubuntu, it's likely they'll have the same paths to copy from and into. To help share settings between the output formats, or even to share between multiple tasks of the same type, this plugin exposes an extension that which will propagate to the tasks. Any settings set on the extension, will serve as defaults, while values on the task will take precedence. Any copy specs, e.g. from(), will apply to all tasks irrelevant of what the task specifies.
apply plugin: 'nebula.ospackage-base'
ospackage {
release '3'
os = LINUX // only applied to RPM
prefix '/opt/local' // also only applied to RPM
into '/opt/app1'
from ('dist') {
user 'builds'
exclude '**/*.rb'
}
}
task app1Rpm(type: Rpm) {
packageName = 'foo'
arch = I386
}
task app1Deb(type: Deb) {
}
Built on top of the os-package-base plugin, the os-package plugin automatically creates two tasks, buildRpm and buildDeb. This is useful when the project defaults are good and any configuration can be put into the ospackage extension. It leverages the fact that most project have no need to customize on a per-package-type basis and want a package for each platform supported.
apply plugin: 'nebula.ospackage'
ospackage {
release '3'
os = LINUX // only applied to RPM
into '/opt/app1'
from ('dist') {
user 'builds'
exclude '**/*.rb'
}
}
// buildRpm and buildDeb are implicitly created, but can still be configured if needed
buildRpm {
arch = I386
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.netflix.nebula:gradle-ospackage-plugin:1.12.2'
}
}
apply plugin: 'nebula.ospackage'
ospackage {
packageName = 'foo'
version = '1.2.3'
release = '1'
arch = I386
os = LINUX
installUtils file('scripts/rpm/utils.sh')
preInstall file('scripts/rpm/preInstall.sh')
postInstall file('scripts/rpm/postInstall.sh')
preUninstall 'touch /tmp/myfile'
postUninstall file('scripts/rpm/postUninstall.sh')
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') {
// Creating directory entries (or not) in the RPM is normally left up to redline-rpm library.
// Use this to explicitly create an entry -- for setting directory fileMode on system directories.
createDirectoryEntry = true
fileMode = 0500
into 'home'
}
from('endorsed') {
// Will tell redline-rpm not to auto create directories, which
// is sometimes necessary to avoid rpm directory conflicts
addParentDirs = false
into '/usr/share/tomcat/endorsed'
}
}
buildRpm {
requires('bar', '2.2', GREATER | EQUAL)
requires('baz', '1.0.1', LESS)
link('/etc/init.d/foo’, '/opt/foo/bin/foo.init')
}
buildDeb {
requires('bat', '1.0.1')
link('/etc/init.d/foo', '/opt/foo/bin/foo.upstart')
}
Built with Oracle JDK7 Tested with Oracle JDK8
Gradle Version | Works |
---|---|
2.2.1 | yes |
2.3 | yes |
2.4 | yes |
2.5 | yes |
2.6 | yes |
2.7 | yes |
2.8 | yes |
2.9 | yes |
2.10 | yes |
Copyright 2014-2016 Netflix, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.