Manage your spring factories (META-INF/spring.factories
) by annotation much like AutoService
does for META-INF/services
.
-
@SpringFactory accepts multiple classes
-
Gradle incremental annotation processing supported
-
Separate artifacts for annotation processor and annotations
-
Bill of Materials artifact included
Gradle build.gradle
dependencies {
annotationProcessor platform('io.github.joke.spring-factory:bom:1.0.0')
annotationProcessor 'io.github.joke.spring-factory:processor'
compileOnly platform('io.github.joke.spring-factory:bom:1.0.0')
compileOnly 'io.github.joke.spring-factory:annotations'
}
Maven pom.xml
<build>
<dependencies>
<dependency>
<groupId>io.github.joke.spring-factory</groupId>
<artifactId>annotations</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<annotationProcessorPaths>
<path>
<groupId>io.github.joke.spring-factory</groupId>
<artifactId>processor</artifactId>
<version>1.0.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
Manage your Spring auto META-INF/spring.factories
by annotation.
Simply annotate your classes and let the annotation processor do the rest.
This works in the same fashion as AutoService
but for Spring’s factory meta files.
Usage example
@SpringFactory(EnableAutoConfiguration.class)
public class MyAutoConfiguration {}
@SpringFactory({EnableAutoConfiguration.class, AutoConfigureDataMongo.class})
public class MyMongoAutoConfiguration {}
Generated output
META-INF/spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
package.name.of.first.class.MyAutoConfiguration,\
package.name.of.second.class.MyMongoAutoConfiguration
org.springframework.boot.test.autoconfigure.data.mongo.AutoConfigureDataMongo=\
package.name.of.second.class.MyMongoAutoConfiguration