Skip to content

Fluid Entity Gradle

Daan van Yperen edited this page Jul 13, 2021 · 11 revisions

Fluid Entity API Gradle installation

Gradle module setup

The Fluid API is required to compile your main game logic, and the components are required to generate the Fluid API, so they cannot all be in the same gradle module.

You need to separate your components into a separate gradle module, and add the fluid plugin to your main game module.

image

By example

Step by step

  1. Start with a gradle project set up to compile artemis-odb.

  2. Add the plugin to the buildscript dependencies.

    (You might need to first add artemisVersion to gradle.properties.)
    
    dependencies {
        // lib for artemis-odb fluid.
        classpath "net.onedaybeard.artemis:artemis-fluid-gradle-plugin:$artemisVersion"
    }
    
  3. Add a new module to your main build.gradle:

    project(":components") {
        apply plugin: "java"
    }
    
  4. Include the new module in settings.gradle

  5. Add any pre-existing components to <project root>/components/src directory.

  6. Create <project root>/components/build.gradle:

    apply plugin: "java"
    
    sourceCompatibility = 1.7
    [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
    sourceSets.main.java.srcDirs = ["src/"]
    eclipse.project {
        name = appName + "-components"
    }
  7. Include the new component module as a dependency to whatever module is going to hold your game systems. If you are using libGDX's code generator, this is the :core module.

    project(":core") {
        apply plugin: "java"
    
        dependencies {
            compile project(":components")
  8. Add the following to the gradle configuration for this core module (example: core/build.gradle)

    apply plugin: "artemis-fluid"
    
    ext {
        fluidOutputDir = file("$buildDir/generated-sources/fluid/")
    }
    
    // Replace existing line.
    sourceSets.main.java.srcDirs = ["src/",fluidOutputDir]
    
    fluid {
         generatedSourcesDirectory = fluidOutputDir
         classpath = sourceSets.main.compileClasspath
    
         // optional parameters. Uncomment to activate.
         // preferences.prefixComponentGetter = "_" // prefix for E::[get]pos()
         // preferences.prefixComponentCreate = "" // prefix for E::[]pos()
         // preferences.prefixComponentHas = "has" // prefix for E::[has]Pos()
         // preferences.prefixComponentRemove = "remove" // prefix for E::[remove]Pos()
         // preferences.generateTagMethods = true // add tag convenience methods.
         // preferences.generateGroupMethods = true // add group convenience methods.
         // preferences.generateBooleanComponentAccessors = true // Generate boolean accessors for flag components?
         // preferences.swallowGettersWithParameters = false // global setting. overridden by @Fluid annotation.
    }
    compileJava.dependsOn fluid
    
    // Help intellIJ pick up the generated classes.
    idea.module {
        excludeDirs -= file("$buildDir")
        excludeDirs += file("$buildDir/classes")
        excludeDirs += file("$buildDir/dependency-cache")
        excludeDirs += file("$buildDir/libs")
        excludeDirs += file("$buildDir/tmp")
    }
  9. Run gradle core:compile. If it worked you should find generated source in (core module)/build/generated-sources/fluid/.

See https://github.com/DaanVanYperen/libgdx-artemis-quickstart/commit/11dc6631bc7ce4e79dee6ff93018c8a94ecc7918 for an example

Performance tip

When compiling with gradlew fluid -i, the fluid plugin can be seen scanning loads of extra artifacts. To speed up compilation exclude artifacts using the following preference setting. Alternatively limit the supplied classpath.

fluid {
    preferences.excludeFromClasspath += [
            // speed up compilation by skipping dependencies without components.
            "guava-",
            "reflections-",
            "commons-lang3-",
            "javapoet-",
            "fast-classpath-scanner-",
            "commons-io-",
            "javassist-",
    ]
Clone this wiki locally