This documentation is for an unreleased version of Apache Flink. We recommend you use the latest stable version.
Importing Flink into an IDE #
The sections below describe how to import the Flink project into an IDE for the development of Flink itself. For writing Flink programs, please refer to the Java API and the Scala API quickstart guides.
Whenever something is not working in your IDE, try with the Maven command line first (
mvn clean package -DskipTests) as it might be your IDE that has a bug or is not properly set up.
To get started, please first checkout the Flink sources from one of our repositories, e.g.
git clone https://github.com/apache/flink.git
Ignoring Refactoring Commits #
We keep a list of big refactoring commits in
.git-blame-ignore-revs. When looking at change annotations using
git blame it’s helpful to ignore these. You can configure git and your IDE to do so using:
git config blame.ignoreRevsFile .git-blame-ignore-revs
IntelliJ IDEA #
A brief guide on how to set up IntelliJ IDEA IDE for development of the Flink core. As Eclipse is known to have issues with mixed Scala and Java projects, more and more contributors are migrating to IntelliJ IDEA.
The following documentation describes the steps to set up IntelliJ IDEA 2020.3 (https://www.jetbrains.com/idea/download/) with the Flink sources.
Installing the Scala plugin #
The IntelliJ installation setup offers to install the Scala plugin. If it is not installed, follow these instructions before importing Flink to enable support for Scala projects and files:
- Go to Settings → Plugins and select the “Marketplace” tab.
- Select for and install the “Scala” plugin.
- Restart IntelliJ if prompted.
Importing Flink #
- Start IntelliJ and choose New → Project from Existing Sources.
- Select the root folder of the cloned Flink repository.
- Choose “Import project from external model” and select “Maven”.
- Leave the default options and successively click “Next” until you reach the SDK section.
- If there is no SDK listed, create one using the “+” sign on the top left. Select “JDK”, choose the JDK home directory and click “OK”. Select the most suiting JDK version. NOTE: A good rule of thumb is to select the JDK version matching the active Maven profile.
- Continue by clicking “Next” until finishing the import.
- Right-click on the imported Flink project → Maven → Generate Sources and Update Folders.
Note that this will install Flink libraries in your local Maven repository,
located by default at “/home/$USER/.m2/repository/org/apache/flink/”.
mvn clean package -DskipTestsalso creates the files necessary for the IDE to work but without installing the libraries.
- Build the Project (Build → Make Project).
Code Formatting #
You can configure your IDE to automatically apply formatting on saving with these steps:
- Download the google-java-format plugin v22.214.171.124.
- Open Settings → Plugins, click on the gear icon and select “Install Plugin from Disk”. Navigate to the downloaded zip file and select it.
- In the plugin settings, enable the plugin and change the code style to “AOSP” (4-space indents).
- Remember to never update this plugin to a later version!
- Install the Save Actions plugin.
- Enable the plugin, along with “Optimize imports” and “Reformat file”.
- In the “Save Actions” settings page, set up a “File Path Inclusion” for
.*\.java. Otherwise, you will get unintended reformatting in other files you edit.
Checkstyle For Java #
IntelliJ supports checkstyle within the IDE using the Checkstyle-IDEA plugin.
- Install the “Checkstyle-IDEA” plugin from the IntelliJ plugin repository.
- Configure the plugin by going to Settings → Tools → Checkstyle.
- Set the “Scan Scope” to “Only Java sources (including tests)”.
- Select 8.14 in the “Checkstyle Version” dropdown and click apply. This step is important, don’t skip it!
- In the “Configuration File” pane, add a new configuration using the plus icon:
- Set the “Description” to “Flink”.
- Select “Use a local Checkstyle file”, and point it to
"tools/maven/checkstyle.xml"within your repository.
- Check the box for “Store relative to project location”, and click “Next”.
- Configure the “checkstyle.suppressions.file” property value to
"suppressions.xml", and click “Next”, then “Finish”.
- Select “Flink” as the only active configuration file, and click “Apply” and “OK”.
- Checkstyle will now give warnings in the editor for any Checkstyle violations.
Once the plugin is installed you can directly import
"tools/maven/checkstyle.xml" by going to Settings → Editor → Code Style → Java → Gear Icon next to Scheme dropbox. This will for example automatically adjust the imports layout.
You can scan an entire module by opening the Checkstyle tools window and clicking the “Check Module” button. The scan should report no errors.
Some modules are not fully covered by checkstyle, which include
flink-runtime. Nevertheless, please make sure that code you add/modify in these modules still conforms to the checkstyle rules.
Checkstyle For Scala #
Enable scalastyle in IntelliJ by selecting Settings → Editor → Inspections, then searching for “Scala style inspections”. Also place
"tools/maven/scalastyle-config.xml" in the
Copyright Profile #
Each file needs to include the Apache license as a header. This can be automated in IntelliJ by adding a Copyright profile:
Open Settings → Editor → Copyright → Copyright Profiles.
Add a new profile naming it
Add the following text as the license text:
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Go to Editor → Copyright and choose the
Apacheprofile as the default profile for this project.
Apply the changes.
This section lists issues that developers have run into in the past when working with IntelliJ:
- Compilation fails with
invalid flag: --add-exports=java.base/sun.net.util=ALL-UNNAMED
This means that IntelliJ activated the
java11 profile despite an older JDK being used.
Open the Maven tool window (View → Tool Windows → Maven), uncheck the
java11 profile and reimport the project.
- Compilation fails with
cannot find symbol: symbol: method defineClass(...) location: class sun.misc.Unsafe
This means that IntelliJ is using JDK 11 for the project, but you are working on a Flink version which doesn’t support Java 11. This commonly happens when you have set up IntelliJ to use JDK 11 and checkout older versions of Flink (<= 1.9). Open the project settings window (File → Project Structure → Project Settings: Project) and select JDK 8 as the project SDK. You may have to revert this after switching back to the new Flink version if you want to use JDK 11.
- Examples fail with a
NoClassDefFoundErrorfor Flink classes.
This is likely due to Flink dependencies being set to provided, resulting in them not being put automatically on the
You can either tick the “Include dependencies with ‘Provided’ scope” box in the run configuration, or create a test
that calls the
main() method of the example (
provided dependencies are available on the test classpath).
NOTE: From our experience, this setup does not work with Flink due to deficiencies of the old Eclipse version bundled with Scala IDE 3.0.3 or due to version incompatibilities with the bundled Scala version in Scala IDE 4.4.1.
We recommend to use IntelliJ instead (see above)
A brief guide on how to set up PyCharm for development of the flink-python module.
The following documentation describes the steps to setup PyCharm 2019.1.3 (https://www.jetbrains.com/pycharm/download/) with the Flink Python sources.
Importing flink-python #
If you are in the PyCharm startup interface:
- Start PyCharm and choose “Open”.
- Select the flink-python folder in the cloned Flink repository-
If you have used PyCharm to open a project:
- Select File → Open.
- Select the flink-python folder in the cloned Flink repository.
Checkstyle For Python #
The Python code checkstyle of Apache Flink should create a flake8 external tool in the project.
- Install the flake8 in the used Python interpreter(refer to (https://pypi.org/project/flake8/).
- Select “PyCharm → Preferences… → Tools → External Tools → + (The bottom left corner of the page on the right)”, next configure the external tool.
- Set the “Name” to “flake8”.
- Set the “Description” to “code style check”.
- Set the “Program” to the Python interpreter path(e.g. /usr/bin/python).
- Set the “Arguments” to “-m flake8 --config=tox.ini”
- Set the “Working directory” to “$ProjectFileDir$”
Now, you can check your Python code style by the operation: “Right click in any file or folder in the flink-python project → External Tools → flake8”