Developing midPoint with IntelliJ IDEA
This guide describes how to set up midPoint in IntelliJ IDEA. IDEA impressed most of our development team members and makes out team much more productive.
This guide assumes you’ve cloned the repository and perhaps built it already. The guide only covers IDEA related steps, see also development guidelines and other guides and how-tos.
See the very end of this document for tl;dr/checklist version.
Install JAVA
JDK 11 (LTS) is supported for midPoint 4.0 and newer. You can download from Oracle JDK, but you better check the license. Or you can try more license-friendly releases like OpenJDK from AdoptOpenJDK or Zulu JDK from Azul.
JDK (sometimes called SDK) is necessary for building - JRE (just the runtime) is not enough.
Install IDEA
IDEA is provided in two editions. You can use free Community edition just fine, paid Ultimate Edition offers advanced support for web development and frameworks. Both editions allow building and running midPoint just fine.
-
Download IDEA from jetbrains.com.
-
Select the version for your operating system and edition.
-
Install IntelliJ IDEA on your computer.
Pictures in the guide are mix of both editions, but we will focus on the basics with the Community Edition.
Import of midPoint into IDEA
Importing midPoint into IDEA can be smooth if you have already built it before.
It is possible to clone the project from GitHub directly in IDEA, but especially on Windows it is recommended to use command line to apply project specific Git configuration during the clone. |
It is recommended to first build the project which avoids a few hiccups during the first import. We will show what happens if you don’t and the project can be built from IDEA too and reimported.
-
Run the IDE and choose Open or import. If IDEA opens with existing project use File | Open from the main menu.
-
Find the cloned
midpoint
directory, select it. -
Click OK to confirm.
Wait until the IDE settles and the progress bar at the bottom stops working.
Possible import problems before the first build
-
If you haven’t built the project before (or deleted
~/.m2/repository/com/evolveum
) IDEA can’t fully import the project, because Maven POMs reference midPoint plugins that are not built yet. -
On Windows, it is recommended to exclude IDEA’s working directory and project repository from Windows Defender scanning - IDEA suggests that and offers an automatic fix.
-
Open the Maven panel on the right edge of the window (hidden behind contextual menu in the picture). Normally the list of Maven projects is flat, if you prefer it to follow the directory structure, click on the Maven Options menu.
-
Check Group Modules to change the visualization of Maven projects structure.
IDEA JDK setup
Before we continue we will check that we’re using the right JDK in IDEA. In the menu, choose File | Project Structure… to open the Project Structure window.
-
Choose Project section in the Project structure window.
-
Check that Project SDK shows JDK 11.
-
If not, click Edit and set JDK as described on this help page.
-
Alternatively you can access JDK setting via SDKs section on the left.
-
Check the Project language level - normally it would be fine to use the level for JDK 11, but as of June 2020 we still secretly (but not officially anymore!) support JDK 8.
Setting Maven build
We may run the Maven build from IDEA, even the first before the project is synced properly.
-
We often want to Toggle 'Skip Tests' Mode - icon has to be highlighted - to avoid very long full build.
-
It is also not necessary to build full distribution with IDEA, so you can uncheck dist in Profiles (it’s a bit laggy, be patient or try again).
-
Finally, run the install phase from under the Lifecycle under the root project. It’s easy to locate the project with modules grouped, in the plain list it’s indicated with (root) after the name.
Without the tests and distribution the build can run for around 4-12 minutes.
Phase package is not enough, we need to get midPoint plugins into the local repository under ~/.m2/repository .
|
After this we can reimport the Maven project:
-
Click reimport icon in the Maven panel.
-
This time everything should be synchronized properly.
-
Project window will show the project structure with recognized modules marked accordingly (blue squares). When the change is detected in the POM files IDEA prompts us to reimport the project.
-
Alternatively, we can choose one of the Auto-reload Modes.
Setting generated sources
During the Maven build of import/schema module, Java sources are from schema files.
Unfortunately, the generated directory is not automatically recognized.
This manifests as unrecognized classes from com.evolveum.midpoint.xml…
packages.
To add it manually, follow the steps in the picture:
-
To be sure, open a source file that uses the generated class, e.g.
Action
interface from model-impl module. Notice the unrecognized class. -
Locate
infra/schema/target/generated/cxf
directory, and right-click on it. -
Open Mark Directory as submenu.
-
Click on Generated Sources Root.
After a while (a click to an editor may be needed) the missing files are recognized and the errors disappear.
Running midPoint in IDEA
We will run midPoint as standalone application which is a recommended deployment. It is possible to run midPoint as WAR in Tomcat, but it is more complicated, less realiable and - which is the most important reason - different from the recommended deployment.
Setting up the run configuration
To run the application:
-
Locate the main class
MidPointSpringApplication
, for instance pressCtrl+N
, type mpsa and pressEnter
. -
Click the green run icon.
-
Choose Run (or Debug).
-
The first time the application is run, it will likely fail with the classpath problem. We will fix it soon.
IDEA creates the run configuration and whenever the right run configuration is selected, it’s easy to run it with the icons in the toolbar next to the name of the run configuration, or just press Shift+F10
.
Alternatively you can use Alt+Shift+F10
to show the Run… popup.
Right now we need to edit it:
Click on the dropdown with run configurations in the toolbar and choose Edit Configurations….
Alternatively, press Alt+Shift+F10
and then 0
.
In the run configuration:
-
Save the current configuration so it’s not transient anymore.
-
Check the checkbox named Include dependencies with "Provided" scope.
-
(Optional) Running the application may also fail on the command line being too long (especially on Windows). It is easy to fix with the option name Shorten command line. This is actually offered by IDEA if this happens, so there is no need to do it proactively. The application runs just fine with the shortened classpath, but the classpath information in the log is less helpful.
-
Confirm the changes with OK and run the application again.
-
This time it should not terminate and show log similar to the picture. You may ignore various warnings reported on stderr output (in red).
After a while, open your browser and head to http://localhost:8080 - midPoint application should appear and you can log in with the traditional administrator/5ecr3t combo.
Viewing logs
If something goes wrong it’s time to check the main applicaiton log.
Console output reports the location of midpoint.home
, open the directory, go to log
subdirectory and open midpoint.log
there.
It’s beyond the scope of this article to cover possible problems, but there should be none under normal circumstances.
The console shows very little and it may be preferred to see the logs in the IDE too.
-
Open the run configuration and choose Logs tab.
-
Click the plus icon to add a new log file.
-
Choose the alias for a log file, it will be displayed on its tab.
-
Click the folder icon.
-
Locate the log file.
-
Confirm the location.
-
Confirm the log file configuration.
-
Confirm the run configuration changes.
After restarting the application there will be separate tab Console and midpoint.log. It may take some time after the start of the application before first logs appear.
It may happen that not all logs are shown at first. To fix this:
-
Click on the midpoint.log tab.
-
Click on the log level filter dropdown and choose required level (e.g. all).
Running the tests in IDEA
TODO
TODO
Other IDEA customizations
-
To change the font size in the editor (it may be too small on some screens), see File | Settings | Editor | Font.
Short version (checklist)
Essential setup tasks:
-
Use JDK 11.
-
Run
mvn clean install -DskipTests -P -dist
at least once. -
Import the project into IDEA as Maven project, set your JDK to 11.
-
Set Maven profiles, e.g. disable the dist profile.
-
Mark
infra/schema/target/generated/cxf
directory as generated sources. -
Add run configuration for
MidPointSpringApplication
with Provided dependencies included on the classpath and try to run it (shorten the command line if necessary, e.g. using JAR manifest). -
Disable Maven modules Dummy Connector and Dummy Connector Fake under midPoint Icf Connectors but keep them as IDEA modules (to avoid incomplete refactorings). Try to run test like
TestReconTask
to check the setup.
Now you can perform other setup tasks like copyright headers, database settings, etc.