This is the Spring Framework Plugin of jQAssistant. It provides pre-defined rules for projects using the Spring Framework, e.g.:
-
Spring Boot
-
Package layout, i.e. all classes of a Spring Boot application must be located in the package of the application class or a child package of it.
-
Considers classes annotated with
@SpringBootApplicationand@TestConfigurationconfiguration classes and injectables.
-
-
Spring Components
-
Considers classes annotated with
@Component,@Service,@Repositoryinjectables. -
Considers classes that are returned from
@Beanmethods injectables. -
Considers Spring Data repositories injectables.
-
Verifies dependencies between Spring components, i.e. controllers (must depend on services, repositories or components), services (must depend on other services, repositories or components) and repositories (must depend on other repositories and components).
-
Requires
@Beanmethods to be used from with configuration classes only. -
Requires that JDK classes are not injectables.
-
-
Dependency Injection
-
Prevents field injection (except in tests, in Strict mode)
-
Requires injectables to be assigned to final fields (in Strict mode)
-
Rejects direct instantiation of injectable types, except in tests and
@Beanmethods. -
Ensures that fields of injectable types are not manipulated.
-
Ensures that injectables are never assigned to static fields or accessed via static methods.
-
Recommends to use
@PostConstructand@PreDestroyover implementingInitializingBeanandDisposableBean. -
Recommends to directly inject
BeanFactory,ApplicationContext, andApplicationEventPublisherinstead of implementing callback interfaces.
-
-
Transactions
-
Disallow direct invocation of methods annotated with
@Transactionfrom methods not annotated with that annotation within the same class
-
For more information on jQAssistant see https://jqassistant.org.
- NOTE
-
Starting from jqassistant-spring-plugin v2.0.0, the Spring-Plugin resides under jqassistant-plugin. Therefore, not only the repository location changed but also group id and artifact id were adapted from
com.buschmais.jqassistant.plugin:springtoorg.jqassistant.plugin:jqassistant-spring-plugin. A manual configuration as shown below is required.
To execute rules, you just need to activate the desired group of rules, either "spring-boot:Default" or "spring-boot:Strict"
jqassistant:
plugins:
- group-id: org.jqassistant.plugin (1)
artifact-id: jqassistant-spring-plugin
version: ${jqassistant.spring-plugin.version}
analyze:
groups:
- spring-boot:Strict (2)-
Dependency to the Spring plugin
-
Activates the group "spring-boot:Strict".
-
Moved Plugin from com.buschmais.jqassistant.plugin (core-Distribution) to org.jqassistant.plugin
-
Added concept
spring-security:ConfigurationComponentto label classes annotated by@EnableGlobalAuthentication,@EnableGlobalMethodSecurity,@EnableReactiveMethodSecurity,@EnableWebSecurity,@EnableWebFluxSecurityand@EnableWebMvcSecurityas:Spring:Configuration:Component -
Extended concepts
spring-transaction:TransactionalClassandspring-transaction:TransactionalMethodto accept JEE/JTA annotationjavax.transaction.@Transactional
-
Removed redundant result columns from constraints
spring-injection:BeanProducerMustNotBeInvokedDirectlyandspring-injection:InjectablesShouldBeHeldInFinalFields
-
Added concepts
spring-mvc:ControllerAdviceandspring-mvc:RestControllerAdvice -
Improved the constraints
spring-component:ControllerMustOnlyDependOnServicesRepositories,spring-component:ServiceMustOnlyDependOnServicesRepositoriesandspring-component:RepositoryMustOnlyDependOnRepositoriesto report one row per invalid dependency (issue) -
Fixed false positives for constraint
spring-injection:InjectablesMustOnlyBeHeldInInjectablesfor inner classes (issue) -
Improved constraint
spring-injection:InjectablesShouldBeHeldInFinalFieldsto return theTypedeclaring theFieldandInjectedTypeas the injected field type.
-
Added constraint
spring-injection:BeanProducerMustNotBeInvokedDirectly -
Allow dependencies from any Spring component to
@Componentannotated beans -
Defined primary columns for constraint results for better matching in SonarQube
-
Excluded generated Java types from Spring constraints, therefore the projects needs to extend the concept
java:GeneratedType -
Excluded classes in test artifacts from constraint
spring-injection:InjectablesMustOnlyBeHeldInInjectables
-
fixed false-positive constraint violations for constraint
InjectablesMustNotBeInstantiatedfor constructors invoking constructors from their super class -
the constraint
spring-injection:FieldsOfInjectablesMustNotBeManipulatednow allows manipulating fields from lifecycle callbacks (@PostConstructand@PreDestroy)
-
Added meta-annotated Spring annotations to concepts, e.g.
@SpringBootApplicationwill be also labeled with `Configuration -
Relaxed the constraint
spring-injection:InjectablesMustNotBeInstantiatedsuch that instantiation is allowed from either bean producer methods declared by injectables or non-injectables (issue) -
Relaxed the constraint
spring-injection:FieldsOfInjectablesMustNotBeManipulatedsuch that only fields of injectable types are checked for being written by non-constructor methods (issue) -
The constraints
spring-injection:FieldsOfInjectablesMustNotBeManipulated,spring-injection:InjectablesMustNotBeHeldInStaticVariablesandspring-injection:InjectablesMustNotBeAccessedStaticallyare improved such that also fields are considered where injectable types are injected by interfaces or super classes.
-
Renamed relation representing virtual dependencies between components from DEPENDS_ON to VIRTUAL_DEPENDS_ON (issue)