Flink__Flink1.10.0源码编译

从源码编译Flink需要在本地安装以下基础组件.

  1. 系统环境: MacOS - Darwin localhost 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64
  2. JDK,编译flink1.10.0 需要JDK8 及以上版本。
  3. Maven,Maven3.3.x可以构建Flink,但不能涵盖某些Jar依赖,编译打包可能会有问题。Flink1.10.0推荐使用Maven3.2.5。要构建单元测试,请使用Java 8u51 或更高版本,防止使用单元测试PowerMock时出错。
  4. Git
  5. NodeJs.
  6. Scala: Flink支持Java, Scala,Python3种语言。如果开发者是Java技术栈,没接触过Scala可以不考虑Scala。Flink类库,运行时环境,API有部分是用Scala语言编写的。用户使用的ScalaAPI 和类库的版本需要与Flink的Sacla版本匹配。从Flink1.7及后续版本编译Flink使用Scala2.11(默认)或Scala2.12版本。

构建Flink

1. 下载Flink源码

可以从Flink Release页下载Flink源码 ,或者 Flink Github 克隆源码,然后使用 git checkout release-1.10.0 切到指定分支,我需要的是1.10.0版本。

git clone https://github.com/apache/flink
git checkout release-1.10.0

2. 修改当前用户Maven 'setting.xml' 文件.


    
        nexus-aliyun
        *,!jeecg,!jeecg-snapshots,!mapr-releases
        Nexus aliyun
        http://maven.aliyun.com/nexus/content/groups/public
    

    
        mapr-public
        mapr-releases
        mapr-releases
        https://maven.aliyun.com/repository/mapr-public
    

第1个mirror:使用的是aliyun提供的maven镜像仓库,能够为国内用户加速maven repository的访问

第2个mirror:最重要,由于flink中的flink-filesystems/flink-mapr-fs模块依赖mapr-releases repository提供的jar包,然而由于国内访问mapr-releases repository比较慢,而且所依赖的maprfs-5.2.1-mapr.jar 这个jar包有48MB,flink依赖中最大的一个jar包,故初次编译flink时,往往会由于下载mapr相关依赖超时导致编译失败。因此,aliyun专门有一个镜像仓库代理mapr-releases repository,以期望能让用户更容易地下载mapr相关的jar包。
参考连接

3. 修改flink-runtime-web工程的Pom.xml文件

flink-runtime-web模块引入了frontend-maven-plugin依赖,并安装了node和部分依赖组件,源码编译时一直卡在 [INFO] Running ‘npm ci --cache-max=0 --no-save’ in。Google一把说是网络问题,于是修改了flink-runtime-web模块的pom.xml文件:


    com.github.eirslett
    frontend-maven-plugin
    1.6
    
        
            install node and npm
            
                install-node-and-npm
            
            
                
                https://registry.npm.taobao.org/dist/
                https://registry.npmjs.org/npm/
                v10.9.0
            
        
        
            npm install
            
                npm
            
            
                
                
                install -registry=https://registry.npm.taobao.org --cache-max=0 --no-save
                
                    true
                
            
        
        
            npm run build
            
                npm
            
            
                run build
                
                https://registry.npm.taobao.org
            
        
    
    
        web-dashboard
    

参考连接1
参考连接2

4. 编译Flink源码

比较简单的打包方式是使用下面命令:

mvn clean install -DskipTests

这条打包命令maven会先删除之前已经存在的编译文件,然后再打包编译新的文件。
这条命令运行速度会比较慢,因为打包了一些不常用的jar包,比如"QA", "JavaDocs"等,如果想打包速度快一些,可以执行下面命令:

mvn clean install -DskipTests -Dfast

此命令会跳过"QA", "JavaDocs"等jar包的编译,加快编译打包。还可以指定Hadoop版本,Scala版本等:

mvn clean install -DskipTests -Dfast -Dhadoop.version=2.8.3 -Dscala-2.12

5. 源码编译成功

编译成功的文件会放在flink源码目录/flink-dist/target 目录下:

localhost:target guyue$ ll
total 199104
-rw-r--r--  1 guyue  staff    30B 10 27 16:12 .plxarc
drwxr-xr-x  3 guyue  staff    96B 10 27 16:12 antrun
drwxr-xr-x  2 guyue  staff    64B 10 27 16:13 archive-tmp
-rw-r--r--  1 guyue  staff   490K 10 27 16:13 bash-java-utils.jar
drwxr-xr-x  5 guyue  staff   160B 10 27 16:12 classes
drwxr-xr-x  3 guyue  staff    96B 10 27 16:13 flink-1.10.0-bin
-rw-r--r--  1 guyue  staff    96M 10 27 16:13 flink-dist_2.12-1.10.0.jar
drwxr-xr-x  3 guyue  staff    96B 10 27 16:12 generated-test-sources
drwxr-xr-x  3 guyue  staff    96B 10 27 16:12 maven-archiver
drwxr-xr-x  3 guyue  staff    96B 10 27 16:12 maven-shared-archive-resources
-rw-r--r--  1 guyue  staff   206K 10 27 16:12 original-flink-dist_2.12-1.10.0.jar
drwxr-xr-x  4 guyue  staff   128B 10 27 16:12 temporary
drwxr-xr-x  5 guyue  staff   160B 10 27 16:12 test-classes

遇到的问题

  1. Could not find artifact io.confluent:kafka-schema-registry-client:jar:3.3.1
[ERROR] Failed to execute goal on project flink-avro-confluent-registry: Could not resolve dependencies for project org.apache.flink:flink-avro-confluent-registry:jar:1.10.0: Could not find artifact io.confluent:kafka-schema-registry-client:jar:3.3.1 in nexus-aliyun (http://maven.aliyun.com/nexus/content/groups/public) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn  -rf :flink-avro-confluent-registry

镜像仓库中没有"kafka-schema-registry-client-3.3.1.jar" 依赖,手动从 这里下载,手动安装到本地仓库:

mvn install:install-file -DgroupId=io.confluent -DartifactId=kafka-schema-registry-client -Dversion=3.3.1 -Dpackaging=jar  -Dfile=/Users/guyue/Downloads/kafka-schema-registry-client-3.3.1.jar

再次重新编译。
参考连接
参考连接

你可能感兴趣的:(Flink__Flink1.10.0源码编译)