This knowledge base is for issues that pop-up when developing with IntelliJ IDEA.
Prerequisites: You must have installed and activated IntelliJ IDEA. You also must have cloned the git repo from GitHub (see the README file for the repository you want to work on).
To import your project into IntelliJ IDEA:
Answer: Ensure you have annotation processing on. IntelliJ IDEA → Preferences → Search for "Annotation Processors" → On page check "Enable Annotation Processing".
Answer: Enable the VCS root in preferences.
Answer: `src/integration-tests/` aren't automatically recognized in Gradle as Java source. Add them in preferences.
Answer: Your IDEA files are likely messed-up and you need to re-generate them. First remove any ipr, iws, and iml files from the project's root. For good measure run gradle cleanIdea. Next run gradle idea. Do not run either of these from inside a Docker Container (e.g. openlmis/dev) or using docker-compose.
Answer: Your IDEA doesn't recognize generated classes. In order to change that you need to in Project Window (Alt +1) right click on build → Mark directory as → Cancel Exclusion and again right click on build / gen / buildconfig / src / main → Mark directory as →Generated Source Root. If necessary click on class that can't be imported → alt + enter → select first option.
In order to unit test with IntelliJ you need temporarily copy build/gen/buildconfig/src/main/org.openlmis/BuildConfig.java to src/main/java/org.openlmis.
OLD: The above file is an old version, the latest is at: https://github.com/google/styleguide/blob/gh-pages/intellij-java-google-style.xml
Download the above file and place it in IntelliJ codestyle config directory (for Linux this will be similar to: /home/user/.ideaIC2016.1/config/codestyles). Restart IntelliJ if you have it started. import it as an intelliJ Idea code style XML. Go to File → Settings → Code Style and follow the screenshot below.
Go to File → Settings → Code Style and from the dropdown list select scheme "GoogleStyle".
Running tests in IntelliJ IDEA should work out of the box. If you are getting errors about permissions or Gradle not being able to create directories, the underlying issue is most likely file ownership. If you were running docker-compose as root, it is likely that root has became the owner of the .gradle directory in your project. In order to change ownership back to your user run:
sudo chown <user>:<user> -R .
in the project directory. <user> is your system username.
To find out how not to run Docker as root (e.g. sudo), see the docker cheat sheet.
There are two main obstacles that keep the integration tests from being run outside of the dev docker container:
Steps to work around these obstacles:
Below is a collection of keyboard shortcuts for IntelliJ:
https://resources.jetbrains.com/assets/products/intellij-idea/IntelliJIDEA_ReferenceCard.pdf