如何使用maven为不同的依赖项(Hadoop 0.23.9,2.0.0等)生成不同的构建

时间:2013-08-25 23:25:42

标签: java maven hadoop

我要完成一个小oss project来浏览cli上的hdfs(比如ncdu)。现在我需要解决如何使用不同的依赖关系(因为hadoop有不同的分布)。

对于我的用例,他们的Java API是相同的,所以理论上我只需要替换一些依赖项并逐个构建它们。包括所有单元测试和部署内容,手动操作并不方便。

有没有办法用不同版本执行mvn install 3次?

我需要用这个版本构建它(不是那些具有不同依赖关系的cdh):

  • 0.23.9
  • 2.0.0-cdh4.2.0
  • 2.0.0-cdh4.3.0

我提出的唯一解决方案是拥有配置文件,然后让CI使用不同的配置文件执行mvn install 3次。

像这样:

mvn install -Phadoop-vanillia-0.23.9
mvn install -Phadoop-cdh4.2.0
mvn install -Phadoop-cdh4.3.0

我的pom.xml看起来像这样:

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!-- ... -->
    <profiles>
        <profile>
            <id>hadoop-vanillia-0.23.9</id>
            <properties>
                <hadoop-distribution>vinallia-0.23.9</hadoop-distribution>
                <hadoop.version.generic>0.23.9</hadoop.version.generic>
            </properties>

            <dependencies>
                <dependency>
                    <groupId>org.apache.hadoop</groupId>
                    <artifactId>hadoop-common</artifactId>
                    <version>${hadoop.version.generic}</version>
                </dependency>

                <dependency>
                    <groupId>org.apache.hadoop</groupId>
                    <artifactId>hadoop-hdfs</artifactId>
                    <version>${hadoop.version.generic}</version>
                </dependency>
            </dependencies>
        </profile>

        <profile>
            <id>hadoop-cdh4.2.0</id>
            <properties>
                <hadoop-distribution>cdh4.2.0</hadoop-distribution>
                <hadoop.version.generic>2.0.0-cdh4.2.0</hadoop.version.generic>
                <hadoop.version.mr1>2.0.0-mr1-cdh4.2.0</hadoop.version.mr1>
            </properties>

            <dependencies>
                <dependency>
                    <groupId>org.apache.hadoop</groupId>
                    <artifactId>hadoop-common</artifactId>
                    <version>${hadoop.version.generic}</version>
                </dependency>

                <dependency>
                    <groupId>org.apache.hadoop</groupId>
                    <artifactId>hadoop-hdfs</artifactId>
                    <version>${hadoop.version.generic}</version>
                </dependency>

                <dependency>
                    <groupId>org.apache.hadoop</groupId>
                    <artifactId>hadoop-tools</artifactId>
                    <version>${hadoop.version.mr1}</version>
                </dependency>
            </dependencies>

            <repositories>
                <repository>
                    <id>cloudera</id>
                    <url>https://repository.cloudera.com/artifactory/cloudera-repos/</url>
                </repository>
            </repositories>
        </profile>

        <profile>
            <id>hadoop-cdh4.3.0</id>
            <properties>
                <hadoop-distribution>hadoop-cdh4.3.0</hadoop-distribution>
                <hadoop.version.generic>2.0.0-mr1-cdh4.3.0</hadoop.version.generic>
            </properties>
            <!-- Same then 4.2.0 here ... -->
        </profile>

    </profiles>

    <properties>
        <!-- ... -->
    </properties>

    <dependencies>
        <!-- ... -->
    </dependencies>

    <build>
        <plugins>

            <!-- ... -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>1.4</version>
                <configuration>
                    <programs>
                        <program>
                            <mainClass>${mainClass}</mainClass>
                            <name>nchadoop</name>
                        </program>

                        <!-- put the flavours into different folders: -->
                        <assembleDirectory>${project.build.directory}/appassembler/${hadoop-distribution}/</assembleDirectory>
                    </programs>

                    <!-- ... -->
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

任何想法如何做到这一点更优雅?也许有模块?

0 个答案:

没有答案