IDE guidelines for the Java Rest API
IDE guidelines
The IDE we have used is Intellij.
We recommend that you install the following plugins:
- Lombok - To reduce the amount of boiler-plate code that needs to be written
- Sonarlint - Fix and detect code quality issues
- Spring Assistant - An IntelliJ plugin for aiding Spring development projects
- Spring Tools - Adds Spring support for IDEs
- CheckStyle - Flags up issues with coding style
- google-java-format Formatter - Formats code according to configuration
Plugins used in POM
- Lombok - Avoids need to write e.g. Getter, Setter, RequiredArgsConstructor, ToString, EqualsAndHashCode) in Java classes.
- JaCoCo - A free Java code test coverage library.
- Surefire - Used for reporting purposes (creates reports based on tests in the Java test package).
- fmt-maven-plugin - Formats the java code based on rules in java-google-style.xml.
- Spotbugs - Performs a static analysis of the Java code to check for bugs.
Set up the project
How to import the whole project
In the IDE(We used Intellij) go to File -> New -> Project. Set project SDK to Java 11. Click Next -> Next
Choose the java project folder click finish.
What setup required to get it up and running
Open up the "java" folder and right click on pom.xml and choose "Add as Maven Project". Click on Run -> Edit Configurations Click on Add new Configuration and choose Application/Spring boot Choose the main class as "Application.java" and set any relevant variables, such as to set environment variable for AZURE_COSMOSDB_KEY and set JRE to Java 11. Click OK
Open Application.java file and right click and choose run Application.
Code Quality
Formatter
Install the intellij-java-google-style.xml
formatter configuration file into the IDE from here.
The Java source code will automatically be reformatted to comply with the Google Java Style.
You can override the settings locally in the codebase by adding, for example:
//@formatter:off
manually formatted code
///@formatter:on
Validating and applying formatting
From the <PROJECT-NAME>/java
folder run
- Unix
- Windows
./mvnw com.coveo:fmt-maven-plugin:check
mvnw.cmd com.coveo:fmt-maven-plugin:check
To validate the current formatting. You can then run the below code to apply formatting to the source code.
- Unix
- Windows
./mvnw com.coveo:fmt-maven-plugin:format
mvnw.cmd com.coveo:fmt-maven-plugin:format
Verifying common programming flaws
- Unix
- Windows
./mvnw spotbugs:check
mvnw.cmd spotbugs:check