Maven RPM插件:CentOS 6.5和5.6的不同内容

时间:2015-05-16 19:17:24

标签: maven rpm-maven-plugin

我一直在使用rpm-maven-plugin生成RPM以在CentOS 6.5上安装。现在我需要扩展它以使用在CentOS 5.6上编译的二进制文件打包RPM。我的开发机器是OSX,我希望能够测试CentOS 6.5和5.6的RPM生成。这意味着我应该能够将目标操作系统作为命令行参数传递。关于如何做到这一点的任何想法?

我查看了插件的文档,似乎我需要使用过滤器,但我无法找到如何确定CentOS 5.6和6.5的分类器的值。

谢谢!

1 个答案:

答案 0 :(得分:1)

我最终创建了两个单独的maven-rpm-plugin执行:一个用于CentOS 6.5,另一个用于CentOS 5.6。我还禁止在发布过程中将RPM自动上传到Maven repo,因为两个RPM具有相同的名称。我通过将-Dmaven.deploy.skip = true添加到maven-release-plugin部分来禁用上传。

以下是我的pom.xml的相关摘录(可以使用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>