I am developing a Spring boot application which is built with gradle. There are some beans which should only be part of the application context at development time, let's say some mocks. I understand that Spring profiles can help here.
However, the dev-only classes would still be part of the build and would be rolled out to production and there is a risk that these beans get active by accident.
What is the best way to
- have dev-only beans and
- exclude them from production build?
The solution should work out of the box, thus without setting up additional packages in the dev classpath in the IDE. I would also like to avoid excluding the classes in the gradle build script because this seems also error-prone.
Putting test only sources in src/test/java is a standard practice in Maven and Gradle. Those are completely separated from the normal project sources and only used for testing at build time.
If the classes are in libraries you should define those dependencies as test dependencies.