A Java 6+ annotation processor to validate Spring @Configuration classes
Java
Fetching latest commit…
Cannot retrieve the latest commit at this time.

README.md

spring-configuration-validation-processor Build Status

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

  1. Add the following dependency to your Maven POM:

    <dependencies>
        <dependency>
          <groupId>com.github.pellaton.config-validation-processor</groupId>
              <artifactId>config-validation-processor</artifactId>
              <version>3.0.7</version>
        </dependency>
    </dependencies>
  2. 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.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

  1. Enable annotation processing and annotation processing in editor in the Eclipse project properties (Java Compiler > Annotation Processing) Screenshot
  2. Configure the path to the processor's jar file (Java Compiler > Annotation Processing > Factory Path) Screenshot

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)

  1. Add the jar file containing the annotation processor to the module libraries
  2. Enable annotation processing in the global IntelliJ IDEAD compiler settings
  3. Add the fully qualified class name of the processor to the annotation processors list Screenshot

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)

  1. Add the jar file containing the annotation processor to the project libraries
  2. Enable annotation processing and annotation processing in editor in the project properties
  3. Add the fully qualified class name of the processor to the annotation processors list Screenshot

Perform a release

$ mvn release:prepare release:perform -Darguments=-Dgpg.passphrase=SECRET