4

I am trying to build an RPM package using the maven plugin.

If I add the plugin configuration the RPM package is not made, the manual on the RPM plugin site says the package tag should be RPM however this seems to cause the build to fail saying that this destination is it valid.

Does anyone have any examples they could share?

EDIT The error is Unknown packaging: rpm

<groupId>...</groupId>
<artifactId>...</artifactId>
<version>...</version>
<packaging>rpm</packaging>

<profile>
            <id>local</id>
            <build>
                <resources>
                    <resource>
                        <directory>src/main/resources/properties/dev</directory>
                    </resource>
                    <resource>
                        <directory>src/main/resources/txt</directory>
                    </resource>
                    <resource>
                        <directory>src/main/resources/universal</directory>
                    </resource>
                </resources>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>rpm-maven-plugin</artifactId>
                        <version>2.1-alpha-3</version>
                        <extensions>true</extensions>
                        <executions>
                            <execution>
                                <id>generate-rpm</id>
                                <goals><goal>rpm</goal></goals>
                                <phase>prepare-package</phase>
                            </execution>
                        </executions>
                        <configuration>
                            <summary>...</summary>
                            <name>...</name>
                            <version>...</version>
                            <release>...</release>
                            <vendor>...</vendor>
                            <packager>...</packager>
                            <group>Application</group>
                            <mappings>
                                <mapping>
                                    <directory>/tmp/testing</directory>
                                </mapping>
                            </mappings>
                            <!--<requires>filesystem, bash, grep</requires>-->

                            <description>
                                ...
                            </description>

                            <prepareScript>RPMScripts/prep.bash</prepareScript>
                            <preinstallScript>RPMScripts/preInstall.bash</preinstallScript>
                            <install>RPMScripts/install.bash</install>
                            <postinstall>RPMScripts/postInstall.bash</postinstall>
                            <cleanScript>RPMScripts/clean.bash</cleanScript>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <version>3.1</version>
                        <configuration>
                            <failOnError>true</failOnError>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jar-plugin</artifactId>
                        <version>2.4</version>
                        <configuration>
                            <archive>
                                <manifest>
                                    <addClasspath>true</addClasspath>
                                </manifest>
                            </archive>
                        </configuration>
                    </plugin>
                    <plugin> 
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-dependency-plugin</artifactId>
                        <version>2.8</version>
                        <executions>
                            <execution>
                                <phase>install</phase>
                                <goals>
                                    <goal>copy-dependencies</goal>
                                </goals>
                                <configuration>
                                    <outputDirectory>${project.build.directory}/lib</outputDirectory>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.16</version>
                        <configuration>
                            <skipTests>true</skipTests>
                        </configuration>
                    </plugin>
blong
  • 2,815
  • 8
  • 44
  • 110
anton91
  • 993
  • 2
  • 10
  • 12

2 Answers2

5

The only answers to this question basically say "if packaging of rpm is giving errors, just don't use it". I am running into the exact same thing, so I will try to shed some more light on the issue.

Someone once said "maven doesn't suck, but maven documentation does"

Here is what I have found -

First... the default packaging types aren't the only packaging types you can use in maven, as stated here:

http://books.sonatype.com/mvnref-book/reference/writing-plugins-sect-plugins-lifecycle.html

To define a new lifecycle for a new packaging type, youbll need to configure a LifecycleMapping component in Plexus. In your plugin project, create a META-INF/plexus/components.xml under src/main/resources. In components.xml add the content from Overriding the Default Lifecycle. Set the name of the packaging type under role-hint, and the set of phases containing the coordinates of the goals to bind (omit the version). Multiple goals can be associated with a phase using a comma delimited list.

Using this as a starting point I searched for "plexus" and discovered that is a IoC (Inversion of Control) Component Framework. A bit like Spring (read Martin Fowler's IoC Article) it helps with "dependency injection" which is to say it makes java more flexible about runtime jar and class file identification and loading, especially if such details as the name of the classes are to be configured at runtime in XML files (for example). Which is something Python and Ruby don't really have to worry about because they are not so concerned with knowing everything at compile time as Java is. The plexus/components.xml is just such a file. Also it helps to know that a Maven Plugin is a plexus component - that is, it is a dependency to be injected - in this case that dependency is a jar, which is a zip file full of class files - a class file describes a "java object" or a "plain old java object" also called a POJO. A POJO for use by Maven is a MOJO - so all Maven plug-ins are MOJOs - and the thing which handles plugging in of the plug-in for Maven is Plexus (at least in Maven 2). So lets hunt through the plug-in source code to see if they have a components.xml file with a "role-hint" of rpm.

...and they do... ("use the source, Luke")

we can also use gihub's GIT Blame feature to see who documented what when the "role-hint" was added and what other files were changed at the same time.

github.com - rpm-maven-plugin - blame - 0efd27d3beb64c291b960731fe1bdbbb5dbd938e - src/main/resources/META-INF/plexus/components.xml

[MOJO-1249] Create rpm as primary artifact

Submitted By: Brett Okken Carlos Sanchez committed on Jan 2, 2009

github.com - rpm-maven-plugin - commit - fb9bc1ae7488dc0fa6853cdd874fc907c628122d

3 files where changes at the same time:

src/main/java/org/codehaus/mojo/rpm/RPMMojo.java

src/main/resources/META-INF/plexus/components.xml

src/site/apt/usage.apt

The usage.apt file is the documentation and these sections were added

+
+ 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>
+ <extensions>true</extensions>
+ ...
+ </plugin>
+ </plugins>
+ </build>
++-------+

The whole documentation file is:

github.com - rpm-maven-plugin - usage.apt

Since I was curious I looked up "apt markup" -

www.beaglebytes.com - creating-a-document-using-apt-v01.html

Almost Plain Text (APT) is a very simple yet powerful markup language. It is particularly interesting because it enables you to create neatly formatted HTML, RTF, and other output formats from a document that appears to be in plain text. As the documentation says:

APTconvert is a command-line tool that can be used to convert the APT format to HTML, XHTML, PDF, PostScript, (MS Word loadable) RTF, DocBook SGML and DocBook XML.

The APT format (Almost Plain Text) is a simple markup language (like HTML) than can be used to write simple article-like documents (like HTML). Unlike HTML, APT uses as few markup as possible to express the structure of the document. Instead, APT uses paragraph indentation.

hope this helps

B r i a n F e n n e l l

Fenn
  • 81
  • 1
  • 7
  • had more links but not enough points to add them - sorry the links are now criptic. – Fenn Jan 06 '16 at 23:26
  • I added this: rpm-maven-plugin true Applications/System I have this: rpm I get this: 00:49:36 [INFO] + exit 0 00:49:36 [DEBUG] RPM not added as an artifact because project's packaging type is not 'rpm' 00:49:36 [WARNING] Attempt to (de-)serialize anonymous class org.jfrog.hudson.maven2.MavenDependenciesRecorder$1; see: https://jenkins.io/redirect/serialization-of-anonymous-classes/ – user1389698 Mar 01 '19 at 08:55
-1

The error is referencing the line :

<packaging>rpm</packaging>

At issue is the fact that your packaging is actually a plugin construct, not a built-in maven package type. Omitting the line will resolve the error.

blong
  • 2,815
  • 8
  • 44
  • 110
  • 1
    This answer only addresses half of the question. I am having the same issue but cannot get the RPM to be generated. I will +1 if you can explain how to get the RPM to be generated. At present I am getting the debug statement "RPM not added as an artifact because project's packaging type is not 'rpm'" after a successful build. – Psyrus Apr 22 '14 at 15:01
  • Ah, sure thing. I usually refer back to this other question actually: http://stackoverflow.com/q/7883891/320399 (a question of mine). It has really good discussion on it's answers and I actually contributed my own answer to the question that solved the problem for me: http://stackoverflow.com/a/8944570/320399 – blong Apr 24 '14 at 15:41
  • Ah ok, yes I have since worked out (as with your linked question / answers) that adjusting pom to make it an attached artifact ('secondary artifact' i believe this is termed) builds the rpm as I need. I still however, have not worked out how to make it build as a primary artifact with the pom as specified in the question here. Nonetheless, my goal was to build a pom successfully, and as presented in your linked article, does build one. Those links and the different artifact info is useful, if you edit accordingly then I +1. Meanwhile I +1 the linked articles as they are indeed useful. – Psyrus Apr 24 '14 at 16:27
  • Cool, thanks very much! I won't have time to do that today, but I will consider doing so in the future – blong Apr 24 '14 at 16:40
  • I think this is now obsolete answer... https://stackoverflow.com/questions/30515899/the-parameters-sourceencoding-rpm-maven-plugin-are-missing-or-invalid/68728072#68728072 – gunslingor Aug 10 '21 at 13:51
  • Agreed. I've converted my old answer to a "Community wiki" since it can't be deleted. Please feel free to edit and/or re-write this answer. I also recommend readers follow the guidance provided by other answers & users here. – blong Aug 10 '21 at 17:03
  • @blong... pretty sure you can edit the answer... I see an edit button on it, pressed it and it looks like even I can edit it... but I don't want to submit. – gunslingor Sep 15 '21 at 15:03