• 从源码构建 Flink
    • Build Flink
    • 构建PyFlink
    • Dependency Shading
    • Hadoop Versions
      • Pre-bundled versions
      • Custom / Vendor-specific versions
    • Scala Versions
    • Encrypted File Systems
    • Jackson

    从源码构建 Flink

    This page covers how to build Flink 1.9.0 from sources.

    • Build Flink
    • 构建PyFlink
    • Dependency Shading
    • Hadoop Versions
      • Pre-bundled versions
      • Custom / Vendor-specific versions
    • Scala Versions
    • Encrypted File Systems
    • Jackson

    In order to build Flink you need the source code. Either download the source of a release or clone the git repository.

    In addition you need Maven 3 and a JDK (Java Development Kit). Flink requires at least Java 8 to build.

    NOTE: Maven 3.3.x can build Flink, but will not properly shade away certain dependencies. Maven 3.2.5 creates the libraries properly.To build unit tests use Java 8u51 or above to prevent failures in unit tests that use the PowerMock runner.

    To clone from git, enter:

    1. git clone https://github.com/apache/flink

    The simplest way of building Flink is by running:

    1. mvn clean install -DskipTests

    This instructs Maven (mvn) to first remove all existing builds (clean) and then create a new Flink binary (install).

    To speed up the build you can skip tests, QA plugins, and JavaDocs:

    1. mvn clean install -DskipTests -Dfast

    如果您想构建一个可用于pip安装的PyFlink包,您需要先构建Flink的Jar包,如构建Flink中所述。之后,进入Flink源码根目录,并执行以下命令,构建PyFlink的源码发布包和wheel包:

    1. cd flink-python; python3 setup.py sdist bdist_wheel

    构建好的源码发布包和wheel包位于./flink-python/dist/目录下。它们均可使用pip安装,比如:

    1. pip install dist/*.tar.gz

    Dependency Shading

    Flink shades away some of the libraries it uses, in order to avoid version clashes with user programs that use different versions of these libraries. Among the shaded libraries are Google Guava, Asm, Apache Curator, Apache HTTP Components, Netty, and others.

    The dependency shading mechanism was recently changed in Maven and requires users to build Flink slightly differently, depending on their Maven version:

    Maven 3.1.x and 3.2.xIt is sufficient to call mvn clean install -DskipTests in the root directory of Flink code base.

    Maven 3.3.xThe build has to be done in two steps: First in the base directory, then in the distribution project:

    1. mvn clean install -DskipTests
    2. cd flink-dist
    3. mvn clean install

    Note: To check your Maven version, run mvn —version.

    Hadoop Versions

    Flink has optional dependencies to HDFS and YARN which are both dependencies from Apache Hadoop. There exist many different versions of Hadoop (from both the upstream project and the different Hadoop distributions). If you are using an incompatible combination of versions, exceptions may occur.

    Flink can be built against any Hadoop version >= 2.4.0, but depending on the version it may be a 1 or 2 step process.

    Pre-bundled versions

    To build against Hadoop 2.4.1, 2.6.5, 2.7.5 or 2.8.3, it is sufficient to run (e.g., for version 2.6.5):

    1. mvn clean install -DskipTests -Dhadoop.version=2.6.5

    To package a shaded pre-packaged Hadoop jar into the distributions /lib directory, activate the include-hadoop profile`:

    1. mvn clean install -DskipTests -Pinclude-hadoop

    Custom / Vendor-specific versions

    If you want to build against Hadoop version that is NOT 2.4.1, 2.6.5, 2.7.5 or 2.8.3,then it is first necessary to build flink-shaded against this version.You can find the source for this project in the Additional Components section of the download page.

    Note If you want to build flink-shaded against a vendor specific Hadoop version, you first have to configure thevendor-specific maven repository in your local maven setup as described here.

    Run the following command to build and install flink-shaded against your desired Hadoop version (e.g., for version 2.6.5-custom):

    1. mvn clean install -Dhadoop.version=2.6.5-custom

    After this step is complete, follow the steps for Pre-bundled versions.

    Scala Versions

    Info Users that purely use the Java APIs and libraries can ignore this section.

    Flink has APIs, libraries, and runtime modules written in Scala. Users of the Scala API and libraries may have to match the Scala version of Flink with the Scala version of their projects (because Scala is not strictly backwards compatible).

    Since version 1.7 Flink builds with Scala version 2.11 (default) and 2.12.

    To build FLink against Scala 2.12, issue the following command:

    1. mvn clean install -DskipTests -Dscala-2.12

    Encrypted File Systems

    If your home directory is encrypted you might encounter a java.io.IOException: File name too long exception. Some encrypted file systems, like encfs used by Ubuntu, do not allow long filenames, which is the cause of this error.

    The workaround is to add:

    1. <args>
    2. <arg>-Xmax-classfile-name</arg>
    3. <arg>128</arg>
    4. </args>

    in the compiler configuration of the pom.xml file of the module causing the error. For example, if the error appears in the flink-yarn module, the above code should be added under the <configuration> tag of scala-maven-plugin. See this issue for more information.

    Jackson

    Multiple Flink components use Jackson. Older versions of jackson (<2.10.1) are subject to a variety of security vulnerabilities.

    Flink 1.9.2+ offers an opt-in profile (use-jackson-2.10.1) for building Flink against Jackson 2.10.1; including jackson-annotations, jackson-core and jackson-databind.

    Usage: mvn package -Puse-jackson-2.10.1

    When you build a maven application against this Flink version it is recommended to bump the maven-shade-plugin version to at least 3.1.1 to prevent packaging errors.