mavenrpm-maven-plugin

Maven RPM plugin: Different content for CentOS 6.5 and 5.6


I have been using rpm-maven-plugin to generate RPMs to install on CentOS 6.5. Now I need to extend it to package an RPM with binaries compiled on CentOS 5.6. My development machine is OSX and I would like to be able to test RPM generation for CentOS 6.5 and 5.6 on it. Which means that I should be able to pass the target OS as a command line parameter. Any ideas on how to do this?

I looked through the plugin's documentation and it seems like I need to use filter, but nowhere I can find how to determine the value for that classifier for CentOS 5.6 and 6.5.

Thanks!


Solution

  • I ended up creating two separate maven-rpm-plugin executions: one - for CentOS 6.5 and one - for CentOS 5.6. I also disabled automatic uploading of RPMs to Maven repo during release process because the two RPMs had the same name. I disabled uploading by adding -Dmaven.deploy.skip=true to maven-release-plugin section.

    Here is a relevant excerpt from my pom.xml (can be executed with mvn package):

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>rpm-maven-plugin</artifactId>
                    <version>2.2.0</version>
                </plugin>
    
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-release-plugin</artifactId>
                    <version>2.5.2</version>
                    <configuration>
                        <arguments>-Dmaven.deploy.skip=true</arguments>
                        <preparationGoals>clean install</preparationGoals>
                        <pushChanges>false</pushChanges>
                        <localCheckout>true</localCheckout>
                        <!--Disable deployment at the end because CentOS 5.6 and 6.5 profile artifacts will collide-->
                        <goals></goals>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    
        <plugins>
    
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>rpm-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>CentOS-5.6</id>
                        <goals>
                            <goal>attached-rpm</goal>
                        </goals>
                        <configuration>
                            <name>${rpmName}</name>
                            <needarch>x86_64</needarch>
                            <workarea>target/rpm/centos-5.6</workarea>
                            <group>CollectD</group>
                            <defaultDirmode>755</defaultDirmode>
                            <defaultFilemode>755</defaultFilemode>
                            <defaultUsername>root</defaultUsername>
                            <defaultGroupname>root</defaultGroupname>
                            <mappings>
                                <!-- Root directory -->
                                <mapping>
                                    <directory>${installDir}</directory>
                                    <directoryIncluded>true</directoryIncluded>
                                    <sources>
                                        <source>
                                            <location>${project.build.directory}/classes/centos-5.6/collectd</location>
                                            <excludes>
                                                <exclude>etc/*</exclude>
                                            </excludes>
                                        </source>
                                    </sources>
                                </mapping>
                                <!-- Overwrite configurations with the right file permissions -->
                                <mapping>
                                    <directory>${installDir}/etc</directory>
                                    <directoryIncluded>false</directoryIncluded>
                                    <configuration>true</configuration>
                                    <sources>
                                        <source>
                                            <location>${project.build.directory}/classes/centos-5.6/collectd/etc</location>
                                        </source>
                                    </sources>
                                    <filemode>644</filemode>
                                </mapping>
                                <!-- local output directories for logging and so on -->
                                <mapping>
                                    <directory>${installDir}/var/log</directory>
                                    <directoryIncluded>true</directoryIncluded>
                                </mapping>
                                <mapping>
                                    <directory>${installDir}/var/lib</directory>
                                    <directoryIncluded>true</directoryIncluded>
                                </mapping>
                                <mapping>
                                    <directory>${installDir}/var/run</directory>
                                    <directoryIncluded>true</directoryIncluded>
                                </mapping>
                                <!-- collectd service startup script -->
                                <mapping>
                                    <directory>/etc/init.d</directory>
                                    <directoryIncluded>false</directoryIncluded>
                                    <sources>
                                        <source>
                                            <location>${project.build.directory}/classes/centos-common/init.d/collectd</location>
                                        </source>
                                    </sources>
                                </mapping>
                            </mappings>
                        </configuration>
                    </execution>
                    <execution>
                        <id>CentOS-6.5</id>
                        <goals>
                            <goal>attached-rpm</goal>
                        </goals>
    
                        <configuration>
                            <name>${rpmName}</name>
                            <needarch>x86_64</needarch>
                            <workarea>target/rpm/centos-6.5</workarea>
                            <group>CollectD</group>
                            <defaultDirmode>755</defaultDirmode>
                            <defaultFilemode>755</defaultFilemode>
                            <defaultUsername>root</defaultUsername>
                            <defaultGroupname>root</defaultGroupname>
                            <mappings>
                                <!-- Root directory -->
                                <mapping>
                                    <directory>${installDir}</directory>
                                    <directoryIncluded>true</directoryIncluded>
                                    <sources>
                                        <source>
                                            <location>${project.build.directory}/classes/centos-6.5/collectd</location>
                                            <excludes>
                                                <exclude>etc/*</exclude>
                                            </excludes>
                                        </source>
                                    </sources>
                                </mapping>
                                <!-- Overwrite configurations with the right file permissions -->
                                <mapping>
                                    <directory>${installDir}/etc</directory>
                                    <directoryIncluded>false</directoryIncluded>
                                    <configuration>true</configuration>
                                    <sources>
                                        <source>
                                            <location>${project.build.directory}/classes/centos-6.5/collectd/etc</location>
                                        </source>
                                    </sources>
                                    <filemode>644</filemode>
                                </mapping>
                                <!-- local output directories for logging and so on -->
                                <mapping>
                                    <directory>${installDir}/var/log</directory>
                                    <directoryIncluded>true</directoryIncluded>
                                </mapping>
                                <mapping>
                                    <directory>${installDir}/var/lib</directory>
                                    <directoryIncluded>true</directoryIncluded>
                                </mapping>
                                <mapping>
                                    <directory>${installDir}/var/run</directory>
                                    <directoryIncluded>true</directoryIncluded>
                                </mapping>
                                <!-- collectd service startup script -->
                                <mapping>
                                    <directory>/etc/init.d</directory>
                                    <directoryIncluded>false</directoryIncluded>
                                    <sources>
                                        <source>
                                            <location>${project.build.directory}/classes/centos-common/init.d/collectd</location>
                                        </source>
                                    </sources>
                                </mapping>
                            </mappings>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>