Class GenerateBuildConfigTask

java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
app.spellscroll.task.GenerateBuildConfigTask
All Implemented Interfaces:
Comparable<org.gradle.api.Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.TaskInternal, org.gradle.api.Named, org.gradle.api.plugins.ExtensionAware, org.gradle.api.Task, org.gradle.util.Configurable<org.gradle.api.Task>

@CacheableTask public abstract class GenerateBuildConfigTask extends org.gradle.api.DefaultTask
Gradle task that generates a Java constants class containing plugin metadata.

The generated class is named {PluginName}Constants (e.g. MyPluginConstants) and is placed in the package derived from project.group. It exposes three public static final String fields: PLUGIN_ID, PLUGIN_VERSION, and PLUGIN_NAME.

Example output for group = 'com.example' and pluginName = 'My Plugin':


 package com.example;

 public final class MyPluginConstants {
     public static final String PLUGIN_ID      = "com.example.my-plugin";
     public static final String PLUGIN_VERSION = "1.1.0";
     public static final String PLUGIN_NAME    = "My Plugin";

     private MyPluginConstants() {}
 }
 

This task is annotated CacheableTask and only reruns when the build file or any of its inputs change. It is wired automatically into compileJava by SpellscrollGradlePlugin.

  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.gradle.api.Named

    org.gradle.api.Named.Namer
  • Field Summary

    Fields inherited from interface org.gradle.api.Task

    TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Generates the {PluginName}Constants.java source file.
    abstract org.gradle.api.file.RegularFileProperty
    The project's build.gradle file, declared as an input so the task reruns whenever the build script changes.
    abstract org.gradle.api.file.DirectoryProperty
    The directory into which the generated .java file is written.
    abstract org.gradle.api.provider.Property<String>
    The plugin identifier (registered at Spellscroll.app under "Developer Tools") This identifier is always an all-lowercase alphanumeric only string.
    abstract org.gradle.api.provider.Property<String>
    Human-readable plugin name (e.g.
    abstract org.gradle.api.provider.Property<String>
    Plugin version string (e.g.
    abstract org.gradle.api.provider.Property<String>
    Gradle project.group value used to derive the package name of the generated class.

    Methods inherited from class org.gradle.api.DefaultTask

    compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesService

    Methods inherited from class org.gradle.api.internal.AbstractTask

    acceptServiceReferences, appendParallelSafeAction, doNotTrackState, doNotTrackStateIf, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonsNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, restoreOnlyIf, restoreTaskActions, setImpliesSubProjects

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.gradle.api.Task

    doNotTrackState, notCompatibleWithConfigurationCache
  • Constructor Details

    • GenerateBuildConfigTask

      public GenerateBuildConfigTask()
  • Method Details

    • getPluginId

      @Input public abstract org.gradle.api.provider.Property<String> getPluginId()
      The plugin identifier (registered at Spellscroll.app under "Developer Tools") This identifier is always an all-lowercase alphanumeric only string. Embedded as PLUGIN_ID in the generated class.
      Returns:
      the plugin ID input property
    • getPluginName

      @Input public abstract org.gradle.api.provider.Property<String> getPluginName()
      Human-readable plugin name (e.g. My Plugin). Used to derive the generated class name and embedded as PLUGIN_NAME.
      Returns:
      the plugin name input property
    • getPluginVersion

      @Input public abstract org.gradle.api.provider.Property<String> getPluginVersion()
      Plugin version string (e.g. 1.0.0). Embedded as PLUGIN_VERSION in the generated class.
      Returns:
      the plugin version input property
    • getProjectGroup

      @Input public abstract org.gradle.api.provider.Property<String> getProjectGroup()
      Gradle project.group value used to derive the package name of the generated class. An empty or unspecified group produces a default-package class.
      Returns:
      the project group input property
    • getBuildFile

      @InputFile @PathSensitive(NONE) public abstract org.gradle.api.file.RegularFileProperty getBuildFile()
      The project's build.gradle file, declared as an input so the task reruns whenever the build script changes.
      Returns:
      the build file input property
    • getOutputDir

      @OutputDirectory public abstract org.gradle.api.file.DirectoryProperty getOutputDir()
      The directory into which the generated .java file is written. Defaults to build/generated/sources/spellscroll/main/java.
      Returns:
      the output directory property
    • generate

      public void generate() throws IOException
      Generates the {PluginName}Constants.java source file.

      Creates the package directory structure as needed, then writes the class with PLUGIN_ID, PLUGIN_VERSION, and PLUGIN_NAME fields.

      Throws:
      IOException - if the output file cannot be written