Gradle integration


Although no Fluxtion gradle plugin is available to scan and generate event processors AOT, gradle’s open architecture makes it easy to integrate a task to wrap a utility. To integrate Fluxtion.scanAndCompileFluxtionBuilders as a build task into a gradle project the following steps are needed:

  • Add Fluxtion compile as a dependency to build.gradle
  • Create a main method that invokes Fluxtion.scanAndCompileFluxtionBuilders(classesDirectory)
  • Register the main method as a task in build.gradle
  • Run the task when you want to regenerate event processors AOT

The sample project demonstrates integrating gradle with the Fluxtion scan and compile utility for AOT generation.

Add dependencies

The build.gradle file declares the dependencies for the project.

dependencies {
    implementation          'com.fluxtion:compiler:9.3.49'
    annotationProcessor     'com.fluxtion:compiler:9.3.49'
}

Create main to wrap Fluxtion scan and compile

The GenerateFluxtion main method calls the scanAndCompileFluxtionBuilders utility.

public class GenerateFluxtion {
    public static void main(String[] args) throws Exception {
        File classesDirectory = new File("build/classes/java/main");
        System.out.println("Scanning " + classesDirectory.getAbsolutePath() + " for builders");
        Fluxtion.scanAndCompileFluxtionBuilders(classesDirectory);
    }
}

Register build task

The build.gradle file register the GenerateFluxtion main as a task for the project.

tasks.register('generateEventProcessors', JavaExec) {
    group = "generation"
    description = "Generate fluxtion event processors"
    classpath = sourceSets.main.runtimeClasspath
    mainClass = 'com.fluxtion.example.generation.gradle.GenerateFluxtion'
}

Generate event processor with task

Generate the processors AOT with

./gradlew generateEventProcessors

./gradlew generateEventProcessors

> Task :generateEventProcessors
> Scanning /fluxtion-examples/gradle-scan-example/build/classes/java/main for builders
> 1: invoking builder com.fluxtion.example.generation.gradle.SampleAotBuilder
> 01-May-24 21:00:50 [main] INFO EventProcessorCompilation - generated EventProcessor file: /fluxtion-examples/gradle-scan-example/src/main/java/com/fluxtion/example/generation/gradle/generated/SampleAot.java

BUILD SUCCESSFUL in 6s
3 actionable tasks: 2 executed, 1 up-to-date