BaseTask

abstract class BaseTask : DefaultTask

Abstract base class for code generation tasks.

This abstract class provides common functionality for code generation tasks, including input and output properties, file generation methods, and type conversion methods.

BaseTask provides the following features:

  • Input and output properties: BaseTask defines several input and output properties that can be used to configure the code generation process. These properties include the package name, module name, output directory, package details, and type.

  • File generation methods: BaseTask provides two methods for generating files: fileSpec() and generate(). The fileSpec() method generates a file spec for the specified file name, and the generate() method generates the code for the file spec.

  • Type conversion methods: BaseTask provides a type() method that can be used to convert a package name and type name to a class name. This method is useful for generating code that references classes from other packages.

To use BaseTask, you should extend it and implement the doTask() method. The doTask() method is where you should perform the actual code generation work.

Example usage:

abstract class MyTask : BaseTask() {

override fun doTask() {
// Perform code generation work here
}
}

class MyTaskImpl : MyTask() {

override fun doTask() {
// Generate a file named "MyClass.kt"
fileSpec("MyClass") {
// Define the contents of the file here
}

// Generate a file named "MyInterface.kt"
fileSpec("MyInterface") {
// Define the contents of the file here
}
}
}

val myTask = MyTaskImpl()
myTask.execute()


This code will generate two files: `MyClass.kt` and `MyInterface.kt`.
The contents of the files will be defined by the `fileSpec()` blocks.

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
@get:Internal
var enabled: Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
@get:Input
@get:Optional
abstract val moduleName: Property<String>

Gets or sets the module name for the generated code.

Link copied to clipboard
@get:OutputDirectory
@get:Optional
abstract val outputDir: DirectoryProperty

Gets or sets the output directory for the generated code.

Link copied to clipboard
@get:Input
@get:Optional
abstract val packageDetails: Property<PackageDetails>

Gets or sets the package details for the generated code.

Link copied to clipboard
@get:Input
@get:Optional
abstract val packageName: Property<String>

Gets or sets the package name for the generated code.

Link copied to clipboard
val state: TaskStateInternal
Link copied to clipboard
val timeout: Property<Duration>

Functions

Link copied to clipboard
open override fun acceptServiceReferences(serviceReferences: MutableSet<ServiceReferenceSpec>)
Link copied to clipboard
open override fun appendParallelSafeAction(action: Action<in Task>)
Link copied to clipboard
open operator override fun compareTo(other: Task): Int
Link copied to clipboard
open override fun configure(closure: Closure<Any>): Task
Link copied to clipboard
open override fun dependsOn(vararg paths: Any): Task
Link copied to clipboard
open override fun doFirst(action: Closure<Any>): Task
open override fun doFirst(action: Action<in Task>): Task
open override fun doFirst(actionName: String, action: Action<in Task>): Task
Link copied to clipboard
open override fun doLast(action: Closure<Any>): Task
open override fun doLast(action: Action<in Task>): Task
open override fun doLast(actionName: String, action: Action<in Task>): Task
Link copied to clipboard
open override fun doNotTrackState(reasonNotToTrackState: String)
Link copied to clipboard
inline fun fileSpec(fileName: String, crossinline block: FileSpec.Builder.() -> Unit)

Generates a file spec for the specified file name.

Link copied to clipboard
open override fun finalizedBy(vararg paths: Any): Task
Link copied to clipboard
fun FileSpec.generate()

Generates the code for the file spec.

Link copied to clipboard
open override fun getActions(): MutableList<Action<in Task>>
Link copied to clipboard
open override fun getAnt(): AntBuilder
Link copied to clipboard
@Internal
open override fun getAsDynamicObject(): DynamicObject
Link copied to clipboard
@Internal
open override fun getConvention(): Convention
Link copied to clipboard
open override fun getDependsOn(): MutableSet<Any>
Link copied to clipboard
open override fun getDescription(): String?
Link copied to clipboard
open override fun getDestroyables(): TaskDestroyables
Link copied to clipboard
open override fun getDidWork(): Boolean
Link copied to clipboard
open override fun getExtensions(): ExtensionContainer
Link copied to clipboard
open override fun getFinalizedBy(): TaskDependency
Link copied to clipboard
open override fun getGroup(): String?
Link copied to clipboard
open override fun getIdentityPath(): Path
Link copied to clipboard
open override fun getInputs(): TaskInputsInternal
Link copied to clipboard
@Internal
open override fun getLifecycleDependencies(): TaskDependencyInternal
Link copied to clipboard
open override fun getLocalState(): TaskLocalState
Link copied to clipboard
open override fun getLogger(): Logger
Link copied to clipboard
open override fun getLogging(): LoggingManager
Link copied to clipboard
open override fun getMustRunAfter(): TaskDependency
Link copied to clipboard
open override fun getName(): String
Link copied to clipboard
open override fun getOnlyIf(): Spec<in TaskInternal>
Link copied to clipboard
open override fun getOutputs(): TaskOutputsInternal
Link copied to clipboard
open override fun getPath(): String
Link copied to clipboard
open override fun getProject(): Project
Link copied to clipboard
Link copied to clipboard
open override fun getRequiredServices(): TaskRequiredServices
Link copied to clipboard
open override fun getSharedResources(): MutableList<ResourceLock>
Link copied to clipboard
open override fun getShouldRunAfter(): TaskDependency
Link copied to clipboard
open override fun getStandardOutputCapture(): StandardOutputCapture
Link copied to clipboard
open override fun getTaskActions(): MutableList<InputChangesAwareTaskAction>
Link copied to clipboard
open override fun getTaskDependencies(): TaskDependencyInternal
Link copied to clipboard
open override fun getTaskIdentity(): TaskIdentity<*>
Link copied to clipboard
open override fun getTemporaryDir(): File
Link copied to clipboard
open override fun getTemporaryDirFactory(): Factory<File>
Link copied to clipboard
open override fun hasProperty(propertyName: String): Boolean
Link copied to clipboard
open override fun hasTaskActions(): Boolean
Link copied to clipboard
Link copied to clipboard
open override fun mustRunAfter(vararg paths: Any): Task
Link copied to clipboard
open override fun notCompatibleWithConfigurationCache(reason: String)
Link copied to clipboard
open override fun onlyIf(onlyIfClosure: Closure<Any>)
open override fun onlyIf(spec: Spec<in Task>)
open override fun onlyIf(onlyIfReason: String, spec: Spec<in Task>)
Link copied to clipboard
open override fun prependParallelSafeAction(action: Action<in Task>)
Link copied to clipboard
open override fun property(propertyName: String): Any?
Link copied to clipboard
open override fun setActions(replacements: MutableList<Action<in Task>>)
Link copied to clipboard
open override fun setDependsOn(dependsOn: MutableIterable<*>)
Link copied to clipboard
open override fun setDescription(description: String?)
Link copied to clipboard
open override fun setDidWork(didWork: Boolean)
Link copied to clipboard
open override fun setFinalizedBy(finalizedByTasks: MutableIterable<*>)
Link copied to clipboard
open override fun setGroup(group: String?)
Link copied to clipboard
open override fun setMustRunAfter(mustRunAfterTasks: MutableIterable<*>)
Link copied to clipboard
open override fun setOnlyIf(onlyIfClosure: Closure<Any>)
open override fun setOnlyIf(spec: Spec<in Task>)
open override fun setOnlyIf(onlyIfReason: String, spec: Spec<in Task>)
Link copied to clipboard
open override fun setProperty(name: String, value: Any)
Link copied to clipboard
open override fun setShouldRunAfter(shouldRunAfterTasks: MutableIterable<*>)
Link copied to clipboard
open override fun shouldRunAfter(vararg paths: Any): TaskDependency
Link copied to clipboard
infix fun String.type(typeName: String): ClassName

Creates a class name for the specified type.

Link copied to clipboard
open override fun usesService(service: Provider<out BuildService<*>>)