spring-configuration-validation-processor
This project provides a Java 6 Annotation processor that emits compiler warnings and errors in case one of the following conditions is encountered in a Spring @Configuration class:
- @Configuration classes must not be final.
- @Configuration classes must have a visible no-arg constructor.
- @Configuration class constructors must not be @Autowired.
- Nested @Configuration classes must be static.
- @Bean methods must not be private.
- @Bean methods must not be final.
- @Bean methods must have a non-void return type.
- @Bean methods should be declared in classes annotated with @Configuration.
- @Bean methods returning a BeanFactoryPostProcessor should be static.
- Only @Bean methods returning a BeanFactoryPostProcessor should be static.
##Quick Start
Maven
- Add the following dependency to your Maven POM:
<dependencies>
<dependency>
<groupId>com.github.pellaton.config-validation-processor</groupId>
<artifactId>config-validation-processor-java11</artifactId>
<!-- For Java 8: <artifactId>config-validation-processor-java8</artifactId> -->
<!-- For Java 7: <artifactId>config-validation-processor-java7</artifactId> -->
<!-- For Java 6: <artifactId>config-validation-processor-java6</artifactId> -->
<version>3.0.7</version>
</dependency>
</dependencies>
- Configure the maven-compiler-plugin to run the annotation processor:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<annotationProcessors>
<annotationProcessor>com.github.pellaton.springconfigvalidation.SpringConfigurationValidationProcessorJava11</annotationProcessor>
<!-- For Java 8: <annotationProcessor>com.github.pellaton.springconfigvalidation.SpringConfigurationValidationProcessorJava8</annotationProcessor> -->
<!-- For Java 7: <annotationProcessor>com.github.pellaton.springconfigvalidation.SpringConfigurationValidationProcessorJava7</annotationProcessor> -->
<!-- For Java 6: <annotationProcessor>com.github.pellaton.springconfigvalidation.SpringConfigurationValidationProcessorJava6</annotationProcessor> -->
</annotationProcessors>
</configuration>
</plugin>
</plugins>
</build>
Gradle
Add the following to your gradle file:
configurations {
annotationProcessor
}
task configureAnnotationProcessing(type: JavaCompile, group: 'build', description: 'Processes the @Configuration classes') {
source = sourceSets.main.java
classpath = configurations.compile + configurations.annotationProcessor
options.compilerArgs = [
"-proc:only",
"-processor", "com.github.pellaton.springconfigvalidation.SpringConfigurationValidationProcessorJava8"
]
destinationDir = buildDir
}
compileJava {
dependsOn configureAnnotationProcessing
}
dependencies {
annotationProcessor 'com.github.pellaton.config-validation-processor:config-validation-processor-java8:3.0.7'
}
Eclipse
- Enable annotation processing and annotation processing in editor in the Eclipse project properties (Java Compiler > Annotation Processing)
- Configure the path to the processor's jar file (Java Compiler > Annotation Processing > Factory Path)
IntelliJ IDEA (Maven Project)
In IntelliJ IDEA, the annotation processor works out if the box in Maven projects configuring the processor in the compiler plugin configuration. Unfortunately, this does not work for Gradle projects :-/
IntelliJ IDEA (Non Maven Project)
- Add the jar file containing the annotation processor to the module libraries
- Enable annotation processing in the global IntelliJ IDEAD compiler settings
- Add the fully qualified class name of the processor to the annotation processors list
Netbeans (Maven Project)
In Netbeans, the annotation processor works out if the box in Maven projects configuring the processor in the compiler plugin configuration.
Netbeans (Non Maven Project)
- Add the jar file containing the annotation processor to the project libraries
- Enable annotation processing and annotation processing in editor in the project properties
- Add the fully qualified class name of the processor to the annotation processors list
Perform a release
$ mvn release:prepare release:perform -Darguments=-Dgpg.passphrase=SECRET