http://mojo.codehaus.org/rpm-maven-plugin/usage.html
Listed below are the various scenarios where the RPM plugin can be used along with the proper way to configure the project(s) involved.
In this scenario, an RPM is generated from the project on demand by executing the goal "rpm:rpm" within a project. The project itself may be configured to produce any sort of packaging, since the RPM is not the primary artifact produced by the project.
If you want the project's artifacts packaged in the RPM, you must generate the RPM as a side effect of the standard lifecycle.
Things which do not work as I envision the 1.0 release working:
In this scenario, an RPM is generated from the project whenever the project is packaged. This must be done whenever the project's primary artifact is intended to be part of the RPM package but can be done anytime. To set up this configuration, include the following lines in the plugin definition in the project's POM file (see the sample configuration for an example of this):
<executions> <execution> <goals> <goal>rpm</goal> </goals> </execution> </executions>
In this scenario, the rpm is not the primary artifact, but will be deployed as a secondary artifact.
<executions> <execution> <goals> <goal>attached-rpm</goal> </goals> </execution> </executions>
In this scenario, the RPM is the primary artifact of the project and is created by executing the phase "package" within the project. If properly configured, this allows the user to execute "mvn package" on a top-level project (which has the items to build and the RPM project as modules) and have Maven package the items to build into jars, wars, ears, etc. and them assemble the RPM of those items for distribution.
The packaging value should be set to "rpm".
<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> ... <packaging>rpm</packaging> ... </project>
The extensions tag for this plugin should be marked true.
<build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>rpm-maven-plugin</artifactId> <version>2.1-alpha-2</version> <extensions>true</extensions> ... </plugin> </plugins> </build>
version
changelogFile
release
copyright
distribution
group
icon
needarch
For passivity purposes, a value of true orfalse will indicate whether the architecture of the build machine will be used. Any other value will set the target architecture of the rpm.
In general, this should only be necessary in the case of compiled code from languages such as C or C++, and should not be specified if the executable content of the package consists only of scripts (such as shell, perl, or python) and/or Java code.
This can be used in conjunction with Source targetArchitecture to flex the contents of the rpm based on the architecture.
targetOS
This can be used in conjunction with Source targetOSName to flex the contents of the rpm based on operating system.
targetVendor
packager
workarea
Beginning with release 2.0-beta-3, sub-directories will be created within the workarea for each execution of the plugin within a life cycle.
defineStatements
The parameters described in this page specify the mapping between the files and directories that exist in the project and the files and directories installed when the RPM package is installed on a system. The RPM build program requires one mapping element for each file to be installed. If the mapping element points to a directory the RPM build program will use the specifications of the mapping for every file in the entire tree starting at the specified directory.
The set of parameters which define a single mapping are contained within amapping tag. The set of allmapping tags are contained within amappings tag. A minimal mapping configuration looks like:
directory
(required)This is the directory where the files in this mapping will be installed when the package is installed. This value must start with/.
configuration
If populated with any value other than false, the value will be used as a modifier to the%config declaration in the spec file. As an example, "<configuration>noreplace</configuration>", would lead to%config(noreplace) being generated in the spec file.
documentation
filemode
(recommended)This is UNIX permissions (file mode) to assign to the files when installed. This value consists of three octal digits representing the access for the owner, the group, and the world. Each digit represents the access allowed and is the sum of 4 for read, 2 for write, and 1 for execute. A common value to use is "644" which provides the owner read/write access and read-only access to everyone else. For more information on this subject, readFile Security, section 3.4 of the Introduction to Linux maintained by the Linux Documentation Project. If not specified, the files retain the filemode assigned to them when copied to the RPM work area.
If none of the file attributes (filemode, username, and groupname) are populated, the defaults (defaultFileMode,defaultUsername,defaultGroupname, anddefaultDirmode) will be used.
username
(recommended)This is the UNIX username to assign to the files when installed. If the named user does not exist when the package is installed, the userroot will be used. If not specified, the files will be owned by the user used to create the package.
If none of the file attributes (filemode, username, and groupname) are populated, the defaults (defaultFileMode,defaultUsername,defaultGroupname, anddefaultDirmode) will be used.
groupname
(recommended)This is the UNIX groupname to assign to the files when installed. If the named group does not exist when the package is installed, the grouproot will be used. If not specified, the files will be owned by the group used to create the package.
If none of the file attributes (filemode, username, and groupname) are populated, the defaults (defaultFileMode,defaultUsername,defaultGroupname, anddefaultDirmode) will be used.
directoryIncluded
If the value is false, the files in this mapping will be listed individually in the spec file.
recurseDirectories
artifact
dependency
If the tag is empty ("<dependency/>"), then all dependencies will be included in the mapping. To limit the dependencies to include in the mapping, you must specify "<includes>", "<excludes>", or both. Each of these elements contains a list of items; for example, the "<includes>" element will have a list of "<include>" items. Each item specifies a single dependency to include or exclude with a string in one of the following two formats:
If no include items are specified, then all dependencies not explicitly excluded are included.
sources
softlinkSources
The parameters described in this page specify the set of files to be copied into the work area for inclusion in the RPM package. By default, files which are related to source control and editor temporary files are excluded.
The set of parameters which define a single file set are contained within asource tag. The set of all source tags are contained within a sources tag. A minimal source configuration looks like:
location
(required)The file or directory to include. If a directory is specified, all files and subdirectories are also included. If the path does not start with/, it is taken to be relative to the project's base directory.
Note that the entire source specification is optional, but each source specification that is present must have this parameter.
noDefaultExcludes
includes
excludes
destination
(optional)If the location is a file (not a directory), this is the name of the file in the rpm. If this value is not provided, the name of thefile will be used.
filter
(optional)Will filter the file(s) and replace special values with properties.
targetArchitecture
(optional)If this is populated, the contents defined by this source will only be included if the value for targetArchitecture matches the target architecture of the rpm.
Beginning with 2.0-beta-3, this is a regular expression. In order to provide backward compatibility, both the architecture (defined for MOJO) and this value will be converted to lower case to make comparison case insensitive.
This can be used to flex the contents of the rpm based on thearchitecture:
targetOSName
(optional)A regular expression that, if populated, indicates that the files defined are only applicable if the expression matches theMOJO.targetOS value.
These parameters relate to the dependencies between RPM packages, not to the dependencies required to build the RPM package contents.
There are three RPM spec file tags related to dependency management:
All three of these tags can appear multiple times in the spec file. To configure these tags in the plugin configuration, specify an element for each instance of the tag in the spec file; the content of the element is the exact text to be placed in the spec file. Please be careful to ensure that version comparison specifications such as<and > are properly specified in the XML file. Here is an example:
<provides> <provide>dump</provide></provides><requires> <require>trash-truck > 1.0</require></requires><conflicts> <conflict>incinerator</conflict></conflicts>
Relocation
Scripts
Each of the scripts can be configured as a Scriptlet, which allows the content of the script to be provided either as a String or File. If both parameters are specified for a script, the external file will be ignored. Before writing scripts for RPM packages, understand thescript docs in Maximum RPM since the operation of the scripts must be done correctly or major problems can occur while installing or removing the package.
Here are examples of passing the content of the script in the pom (using<script>) and in a file (using<scriptFile>):
This script specifies commands to prepare the build. It corresponds to the%prep tag in the spec file.
This script is run before the package is installed. It corresponds to the%pre tag in the spec file.
This script is run as a part of installing the package. It corresponds to the%install tag in the spec file.
This script is run after the package is installed. It corresponds to the%post tag in the spec file.
This script is run before the package is removed. It corresponds to the%preun tag in the spec file.
This script is run after the package is removed. It corresponds to the%postun tag in the spec file.
This script is run when the package is being verified. It corresponds to the%verifyScript tag in the spec file.
This script is run after the package is installed to clean up installation files. It corresponds to the%clean tag in the spec file.
This script is run at the beginning of the transaction. It corresponds to the%pretrans tag in the spec file.
This script is run at the end of the transaction. It corresponds to the%posttrans tag in the spec file.
Triggers
Signatures
This parameter sets the name of the GPG key used to sign the package, and also turns on the signature. Setting this parameter is equivalent to defining the%_gpg_name macro and adding the--sign option to rpmbuild.
This parameter sets the passphrase for the key to sign the rpm. The use of this attribute requiresexpect to be available on the PATH.
==========
example:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>rpm-maven-plugin</artifactId>
<version>2.1x</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>rpm</goal>
</goals>
</execution>
</executions>
<configuration>
<release>uscpstp</release>
<copyright>2012, Citigroup</copyright>
<distribution>ShortTerm etrading Platform</distribution>
<group>Application</group>
<packager>Citigroup</packager>
<version>${project.version}</version>
<prefix>${rpm-install-location}</prefix>
<mappings>
<mapping>
<directory>${rpm-install-location}/bin</directory>
<filemode>755</filemode>
<username>${rpm-user}</username>
<groupname>${rpm-group}</groupname>
<sources>
<source>
<location>${project.build.directory}/bin</location>
<includes>
<include>*.*sh</include>
</includes>
</source>
</sources>
</mapping>
<mapping>
<directory>${rpm-install-location}/config</directory>
<filemode>755</filemode>
<username>${rpm-user}</username>
<groupname>${rpm-group}</groupname>
<sources>
<source>
<location>${project.build.directory}/config</location>
</source>
</sources>
</mapping>
<mapping>
<directory>${rpm-install-location}/lib</directory>
<filemode>755</filemode>
<username>${rpm-user}</username>
<groupname>${rpm-group}</groupname>
<dependency />
<sources>
<source>
<location>
${project.build.directory}/lib/${project.artifactId}-${project.version}.jar
</location>
</source>
</sources>
</mapping>
<mapping>
<directory>${rpm-install-location}/pkg</directory>
<filemode>755</filemode>
<username>${rpm-user}</username>
<groupname>${rpm-group}</groupname>
<sources>
<source>
<location>${project.build.directory}/pkg</location>
<includes>
<include>*.sh</include>
</includes>
</source>
</sources>
</mapping>
</mappings>
<preinstallScript>src/main/scripts/preinstall.sh</preinstallScript>
<postinstall><![CDATA[$RPM_INSTALL_PREFIX/pkg/postinstall.sh < /dev/tty]]></postinstall>
<postremoveScript>src/main/scripts/postuninstall.sh</postremoveScript>
</configuration>
</plugin>