0

我要完成一个小的oss项目来在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

我想出的唯一解决方案是拥有这些配置文件,然后让 CImvn 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>

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

4

0 回答 0