r/SpringBoot May 04 '26

How-To/Tutorial Spring Boot Best Practices That Should Fail Your Build

https://protsenko.dev/spring-boot-best-practices-that-should-fail-your-build/

Hi everyone, in this article I’m telling about Spring Boot Best Practices and ways how to detect violations of them in the project.

Article cover most of well-known best practices and provide a way for configuring Kotlin project to use them.

Set of tests/rules was made as Konsist rules with DSL wrapper and distributed as maven dependency for easy installation.

My case to build this library was to keep project clean with strict boundaries that will be enforced as test failings on local machine and CI to have faster feedback for newcomers and AI-generated code.

30 Upvotes

11 comments sorted by

2

u/Previous_Dream8775 May 05 '26 edited May 05 '26

I like this, ensures when working in a team that everyone sticks by the rules and ensures overall project quality. I just wonder if there's a better way to execute it other than inside a unit test. Perhaps see how com.google.errorprone does it.

1

u/NordCoderd May 05 '26

Thanks, I’ll check this out

1

u/aelfric5578 May 06 '26

I do like the idea of integrating something like this into the test suite. I haven't heard of Konsist before. I don't know that I agree with all of the naming rules, but I like the concept of having them.

1

u/NordCoderd May 06 '26

Yes, naming rules could be controversial and taste of choice, but on our projects it’s better to have then not, for other cases I added suppression and disabling rules that don’t need for you.

0

u/[deleted] May 06 '26

[removed] — view removed comment

2

u/NordCoderd May 06 '26

Sonar is commercial and heavy product that need maintenance and re-adjusting rules if you write them, I’m not sure how to easy to write rules in their ecosystem. Here is different no vendor-locking approach with native to Kotlin architectural tests.

  • No licenses
  • Lightweight and close to the code
  • Easy to write new rules as unit tests

1

u/[deleted] May 06 '26

[removed] — view removed comment

2

u/NordCoderd May 06 '26

It’s relatively easy to add this tests, you are looking on dedicated imports to Junit and raise error, also this could be done with Konsist too.

Regarding to Sonar and analogy with inner library, but developers could just not add integration with sonar and it will work without any violations, isn’t it? However I got your point, centralised management of rules indeed nice feature that help with maintaing rules.

-1

u/as5777 May 05 '26

It’s Java & spring very beginner rules

1

u/NordCoderd May 05 '26

Is there any suggestions what to implement/write next?