由于 hadoop 升级,flink 使用 1.8 版本,需要自定义编译继承 hadoop 3.3.1。
由于历史原因,使用的 flink 版本较低,建议大家使用 flink 1.10 及以上的版本。
一、编译 flink
1、下载源码
git clone -b release-1.8 https://github.com/apache/flink.git
注意:可根据依赖的 flink 版本,切换到对应的分支。
2、编译源码
# skip test
mvn clean install -DskipTests
# 快速编译,skip test、QA、document 等
mvn clean install -DskipTests -Dfast
二、编译 flink-shaded
如果项目需要使用到 hadoop 环境,则需要集成 hadoop 依赖。官方有提供一些 hadoop 版本的集成包,可以将依赖包引入到项目中,或者放置到 flink/lib 目录下。
https://repo.maven.apache.org/maven2/org/apache/flink/flink-shaded-hadoop-2-uber/
第一串数字表示 hadoop 版本,第二串数据表示 flink 版本
因为我们使用的 hadoop 版本为 3.3.1,不在官方提供的范围中,需要我们自己打包编译。
1、下载源码
git clone -b release-8.0 https://github.com/apache/flink-shaded.git
注意:可根据依赖的 flink 版本,切换到对应的分支。
2、编译源码
mvn clean install -Dhadoop.version=3.3.1
注意:如果需要指定hadoop的发行商,需要使用-Pvendor-repos。前提是maven仓库增加了对应发行商的仓库地址,使用帮助见 maven说明
如:
mvn clean install -Pvendor-repos -Dhadoop.version=3.0.0-cdh6.2.0
三、遇到的问题
1、Error creating shaded jar: null: IllegalArgumentException
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.0.0:shade (shade-flink) on project flink-shaded-hadoop-2-uber: Error creating shaded jar: null: IllegalArgumentException -> [Help 1]
解决办法:升级所有 maven-shade-plugin 版本至 3.2.1
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
2、Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project web_nanchang: There are test failures.
[ERROR]
[ERROR] Please refer to E:\maven\web_nanchang\target\surefire-reports for the individual test results.
因为测试代码时遇到错误,它会停止编译。只需要在提示错误模块的pom.xml的<project>里添加以下配置,使得测试出错不影响项目的编译。
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <testFailureIgnore>true</testFailureIgnore> </configuration> </plugin> </plugins> </build>