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
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 #
The following guide has been written for IntelliJ IDEA 2020.3. Some details might differ in other versions. Please make sure to follow all steps accurately.
Importing Flink #
- 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 suitable JDK version. NOTE: A good rule of thumb is to select the JDK version matching the active Maven profile.
- Continue by clicking “Next” until the import is finished.
- Open the “Maven” tab (or right-click on the imported project and find “Maven”) and run
“Generate Sources and Update Folders”. Alternatively, you can run
mvn clean package -DskipTests.
- Build the Project (“Build” → “Build Project”).
Copyright Profile #
Every file needs to include the Apache license as a header. This can be automated in IntelliJ by adding a Copyright profile:
Go to “Settings” → “Editor” → “Copyright” → “Copyright Profiles”.
Add a new profile and name it “Apache”.
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 “Apache” profile as the default profile for this project.
Required Plugins #
Go to “Settings” → “Plugins” and select the “Marketplace” tab. Search for the following plugins, install them, and restart the IDE if prompted:
- Python – Required for PyFlink. If you do not intend to work on PyFlink, you can skip this.
- Save Actions
You will also need to install the google-java-format plugin. However, a specific version of this plugin is required. Download google-java-format v184.108.40.206 and install it as follows. Make sure to never update this plugin.
- Go to “Settings” → “Plugins”.
- Click the gear icon and select “Install Plugin from Disk”.
- Navigate to the downloaded ZIP file and select it.
Code Formatting #
It is recommended to automatically format your code by applying the following settings:
- Go to “Settings” → “Other Settings” → “google-java-format Settings”.
- Tick the checkbox to enable the plugin.
- Change the code style to “Android Open Source Project (AOSP) style”.
- Go to “Settings” → “Other Settings” → “Save Actions”.
- Under “General”, enable your preferred settings for when to format the code, e.g. “Activate save actions on save”.
- Under “Formatting Actions”, select “Optimize imports” and “Reformat file”.
- Under “File Path Inclusions”, add an entry for
.*\.javato avoid formatting other file types.
Checkstyle For Java #
Checkstyle is used to enforce static coding guidelines.
Some modules are not covered by Checkstyle, e.g. flink-core, flink-optimizer, and flink-runtime. Nevertheless, please make sure to conform to the checkstyle rules in these modules if you work in any of these modules.
- Go to “Settings” → “Tools” → “Checkstyle”.
- Set “Scan Scope” to “Only Java sources (including tests)”.
- For “Checkstyle Version” select “8.14”.
- Under “Configuration File” click the “+” icon to add a new configuration.
- Set “Description” to “Flink”.
- Select “Use a local Checkstyle file” and point it to
tools/maven/checkstyle.xmllocated within your cloned repository.
- Select “Store relative to project location” and click “Next”.
- Configure the property
checkstyle.suppressions.filewith the value
suppressions.xmland click “Next”.
- Click “Finish”.
- Select “Flink” as the only active configuration file and click “Apply”.
You can now import the Checkstyle configuration for the Java code formatter.
- Go to “Settings” → “Editor” → “Code Style” → “Java”.
- Click the gear icon next to “Scheme” and select “Import Scheme” → “Checkstyle Configuration”.
- Navigate to and select
tools/maven/checkstyle.xmllocated within your cloned repository.
To verify the setup, click “View” → “Tool Windows” → “Checkstyle” and find the “Check Module” button in the opened tool window. It should report no violations.
Checkstyle For Scala #
Enable Scalastyle as follows:
- Go to “Settings” → “Editor” → “Inspections”.
- Search for “Scala style inspection” and enable it.
Now copy the file
tools/maven/scalastyle-config.xml into the
project/ folder of your
Python for PyFlink #
Working on the flink-python module requires both a Java SDK and a Python SDK. However, IntelliJ IDEA only supports one configured SDK per module. If you intend to work actively on PyFlink, it is recommended to import the flink-python module as a separate project either in PyCharm or IntelliJ IDEA for working with Python.
If you only occasionally need to work on flink-python and would like to get Python to work in IntelliJ IDEA, e.g. to run Python tests, you can use the following guide.
- Follow Configure a virtual environment to create a new Virtualenv Python SDK in your Flink project.
- Find the flink-python module in the Project Explorer, right-click on it and choose “Open Module Settings”. Alternatively, go to “Project Structure” → “Modules” and find the module there.
- Change “Module SDK” to the Virtualenv Python SDK you created earlier.
- Open the file
flink-python/setup.pyand install the dependencies when IntelliJ prompts you to do so.
You can verify your setup by running some of the Python tests located in flink-python.
Common Problems #
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 happens if the “java11” Maven profile is active, but an older JDK version is used. Go to “View” → “Tool Windows” → “Maven” and uncheck the “java11” profile. Afterwards, reimport the project.
Compilation fails with
cannot find symbol: symbol: method defineClass(...) location: class sun.misc.Unsafe
This happens if you are using JDK 11, but are working on a Flink version which doesn’t yet support Java 11 (<= 1.9). Go to “Project Structure” → “Project Settings” → “Project” and select JDK 8 as the Project SDK.
When switching back to newer Flink versions you may have to revert this change again.
Examples fail with a
NoClassDefFoundError for Flink classes.
This happens if Flink dependencies are set to “provided”, resulting in them not being available
on the classpath. You can either check “Include dependencies with ‘Provided’ scope” in your
run configuration, or create a test that calls the
main() method of the example.
Using Eclipse with Flink is currently not supported and discouraged. Please use IntelliJ IDEA instead.
If you intend to work on PyFlink, it is recommended to use PyCharm as a separate IDE for the flink-python module. The following guide has been written for 2019.1.3. Some details might differ in other versions.
Importing flink-python #
- Open the PyCharm IDE and choose (“File” →) “Open”.
- Select the “flink-python” folder within your located repository.
Checkstyle For Python #
Flake8 is used to enforce some coding guidelines.
- Install flake8 for your Python interpreter using
pip install flake8.
- In PyCharm go to “Preferences” → “Tools” → “External Tools”.
- Select the “+” button to add a new external tool.
- Set “Name” to “flake8”.
- Set “Description” to “Code Style Check”.
- Set “Program” to the path of your Python interpreter, e.g.
- Set “Arguments” to
-m flake8 --config=tox.ini.
- Set “Working Directory” to
You can verify the setup by right-clicking on any file or folder in the flink-python project and running “External Tools” → “flake8”.