Share your Java best practices with your team in IntelliJ
Tags: java, productivity, codequality, tutorial
Published: 2022-05-25 05:56:57

**IntelliJ IDEA** stands as one of the most popular IDEs when developing **Java** code. It’s pretty tedious to have accurate numbers, but we can reasonably assume that it belongs to the two top leaders with Eclipse around the world. 

*NB: Keep in mind that this post content also works for Eclipse.* 

Whether you code alone or in **pair/mob-programming** sessions, coding often implies reworking source code to perform refactoring or making it more compliant with some best practices. These practices may:

- already exist in your team, and you consider everyone to know them
- have **not been discussed yet**, but you believe they should be anchored in the project
- target any **topic** of interest for you: Java, a framework like Spring, Architecture, Performance,…

Let’s find out how to **define and share** some best practices with your team in IntelliJ.

### #1 Catch an example of best practice in IntelliJ

First, you’ll have to install the Packmind plugin from the **JetBrains Marketplace** and create an account on [Packmind](https://packmind.com) to get your API key. Set this key into your plugin setting in your IDE. You should be ready in less than 2 minutes.  

Now assume you’re coding and face an example of a best practice that has not been followed. Here is an example with a field injection in **Spring Boot**, since in our context we favor constructor injection instead. But consider you’ll define any practice relevant to your context.

![Suggestion of best practice](https://packmind.com/wp-content/uploads/Proposition2.gif)

Also, note that you can also identify **positive** examples if you think the practice has been followed. It’s relevant to consider both cases to enrich the documentation, it’ll be very appreciated in scenarios such as [onboarding](https://packmind.com/onboard-new-developers-with-your-best-coding-practices/) new developers. 

You can also provide a correction to illustrate how, according to you, the best practice should be followed. Here we illustrate the **constructor injection** pattern:

![Suggestion of best practice](https://packmind.com/wp-content/uploads/Correction.gif)

### #2 Discuss best practices with other developers

These asynchronous contributions happen several times a week and are pushed into the Packmind Web application for a later review. This review is called a **Craft Workshop** and usually occurs once every iteration in a project. This technical retrospective is dedicated to **continuous improvement** regarding the coding practices within a team. 

Packmind is used as a support to show each contribution one by one, inviting each author to comment to the team on their point of view: 


![Best practices listed in Packmind](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w2c61w6lcmjyo89haxr0.png)

In case this is a counter-example of a best practice, you can display the correction so that anyone figures out how you suggest overcoming the issue:

![Correction of a best practice not followed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/74gn3iok4k6z65scbbdd.png)

After internal discussions, you’ll **decide** whether the practice will be validated or not, and that’s how Packmind helps you make technical decisions through collective consensus. 

### #3 Tune Packmind’s automatic algorithm

In case your practice has been validated, you can indicate to Packmind a regular expression pattern that will **detect** whether this is followed or not in the source code. We illustrate with this expression that catches the **@Autowired** annotation on private fields:

![Regular expression annotation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8cr1gn6o755xsqorgsnf.png)

Once you’ve achieved that, all developers in your team will be notified by their Packmind plugin in IntelliJ in case they use this annotation on a private field:

![Suggestion of best practice](https://packmind.com/wp-content/uploads/Suggestions.gif)

That was a quick overview of how you can define best practices in your IntelliJ, thanks to the Packmind plugin. Think as an opportunity to remain focused on your development flow, without switching to another tool to write down some documentation about best practices.

🚀 Want to start sharing best practices with your team? Get started for free on [packmind.com](https://packmind.com).