Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.slne.surf.surfapi.gradle.generators

import dev.slne.surf.surfapi.gradle.generators.pluginfiles.CommonPluginFile
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.InternalSerializationApi
import kotlinx.serialization.KSerializer
Expand All @@ -11,35 +10,40 @@ import kotlinx.serialization.encoding.Encoder
import kotlinx.serialization.json.Json
import org.gradle.api.DefaultTask
import org.gradle.api.NamedDomainObjectContainer
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.CacheableTask
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Nested
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction

@CacheableTask
abstract class GeneratePluginFile : DefaultTask() {
@get:Input
abstract val fileName: Property<String>

@get:Nested
abstract val pluginFile: Property<CommonPluginFile>
@get:Input
abstract val pluginFileJson: Property<String>
Comment on lines 22 to +26

Copilot AI Feb 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileName is still declared as an @Input, but the task no longer uses it (the output path is fully determined by outputFile). This adds unnecessary configuration and affects the task cache key; consider removing fileName entirely or using it to derive outputFile inside the task configuration.

Copilot uses AI. Check for mistakes.

@get:OutputDirectory
abstract val outputDirectory: DirectoryProperty
abstract val outputFile: RegularFileProperty
Comment on lines 28 to +29

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Use OutputFile annotation for RegularFileProperty

The task now exposes outputFile as a RegularFileProperty, but it is still annotated with @OutputDirectory. Gradle validates output property types, so pairing @OutputDirectory with a regular file can cause configuration-time errors (e.g., “Expected a directory but found a file”) or incorrect up-to-date/caching behavior when the task writes a single file. This will surface whenever the task runs on a clean build or with configuration caching enabled. Use @OutputFile for a single file output to match the property type and task behavior.

Useful? React with 👍 / 👎.


Comment on lines 27 to 30

Copilot AI Feb 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

outputFile is a RegularFileProperty but is annotated as @OutputDirectory. Gradle task property validation will treat this as an invalid output type and may fail the build / disable caching. Change the annotation (and import) to @OutputFile (with @get:OutputFile).

Copilot uses AI. Check for mistakes.
@TaskAction
fun generate() {
val pluginFile = pluginFile.get()
if (pluginFile.isApplied()) {
val encoded = json.encodeToString(pluginFile)
outputDirectory.file(fileName).get().asFile.writeText(encoded)
val out = outputFile.get().asFile
val json = pluginFileJson.get()

if (json.isNotBlank()) {
out.parentFile.mkdirs()
out.writeText(json)
} else {
if (out.exists()) out.delete()
}
}

@OptIn(ExperimentalSerializationApi::class)
companion object {
private val json = Json {
val json = Json {
isLenient = true
prettyPrint = true
prettyPrintIndent = " "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import org.gradle.api.DefaultTask
import org.gradle.api.Project
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.OutputDirectory
import org.gradle.api.tasks.TaskAction
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.*
import org.gradle.kotlin.dsl.register
import java.io.IOException
import java.io.InputStreamReader
Expand All @@ -19,6 +16,7 @@ import kotlin.reflect.typeOf

const val PaperLibraryLoaderClassName = "PaperLibraryLoader"

@CacheableTask
abstract class GenerateLibrariesLoaderTask : DefaultTask() {
@get:Input
abstract val packageName: Property<String>
Expand All @@ -28,6 +26,7 @@ abstract class GenerateLibrariesLoaderTask : DefaultTask() {

@TaskAction
fun generate() {
project.delete(outputDirectory)
val loader = LibrariesLoaderGenerator.generate(packageName.get())
loader.writeTo(outputDirectory.get().asFile)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class VelocityPluginFile(project: Project) : CommonPluginFile() {
@Nested
@Optional
var pluginDependencies: NamedDomainObjectContainer<Dependency> =
project.container(Dependency::class.java).apply {
project.objects.domainObjectContainer(Dependency::class.java).apply {
register("surf-api-velocity") {
optional = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,28 @@ abstract class CommonSurfPluginWithPluginFile<E : CommonSurfExtension, F : Commo
val createdPluginFile = createPluginFile(this)
extensions.add("${platformName}PluginFile", createdPluginFile)

val generateTask = tasks.register<GeneratePluginFile>("generate${platformName.uppercaseFirstChar()}PluginFile") {
group = "surf-api"

fileName.set(pluginFileName)
outputDirectory.set(generatedResourcesDirectory)
pluginFile.set(provider {
createdPluginFile.setDefaults(target)
createdPluginFile
})

doFirst {
if (createdPluginFile.isApplied()) {
createdPluginFile.validate()
} else {
logger.warn(
"Plugin file generation is skipped because the plugin file is not applied. " +
"Please check if the plugin file is applied in the build.gradle.kts file."
)
}
val generateTask =
tasks.register<GeneratePluginFile>("generate${platformName.uppercaseFirstChar()}PluginFile") {
group = "surf-api"

fileName.set(pluginFileName)

outputFile.set(generatedResourcesDirectory.map { it.file(pluginFileName) })
Comment on lines +35 to +39

Copilot AI Feb 7, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileName is configured on GeneratePluginFile, but the task implementation no longer uses it (it writes to outputFile). Once fileName is removed/repurposed in the task, this configuration should be dropped to avoid misleading inputs.

Copilot uses AI. Check for mistakes.
pluginFileJson.set(provider {
createdPluginFile.setDefaults(target)

if (createdPluginFile.isApplied()) {
createdPluginFile.validate()
GeneratePluginFile.json.encodeToString<CommonPluginFile>(createdPluginFile)
} else {
logger.warn(
"Plugin file generation is skipped because the plugin file is not applied. " +
"Please check if the plugin file is applied in the build.gradle.kts file."
)
""
}
})
}
}

plugins.withType<JavaPlugin> {
extensions.getByType<SourceSetContainer>().named(SourceSet.MAIN_SOURCE_SET_NAME) {
Expand Down
Loading