Skip to content
Open
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
2 changes: 2 additions & 0 deletions src/main/kotlin/build/buf/gradle/GenerateConfiguration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ internal fun Project.configureGenerate() {
templateFile.set(generateOptions?.let { resolveTemplateFile(it) })
inputFiles.setFrom(obtainDefaultProtoFileSet())
outputDirectory.set(File(project.bufbuildDir, GENERATED_DIR))
bufConfigFile.set(project.bufConfigFile())
v1SyntaxOnly.set(bufV1SyntaxOnly())
}
}

Expand Down
22 changes: 21 additions & 1 deletion src/main/kotlin/build/buf/gradle/GenerateTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ abstract class GenerateTask : AbstractBufExecTask() {
@get:OutputDirectory
internal abstract val outputDirectory: Property<File>

/** The input buf configuration file. */
@get:InputFiles
@get:Optional
@get:PathSensitive(PathSensitivity.RELATIVE)
internal abstract val bufConfigFile: Property<File>

@get:Input
internal abstract val v1SyntaxOnly: Property<Boolean>

@TaskAction
fun bufGenerate() {
val args = listOf("generate", "--output", outputDirectory.get())
Expand All @@ -67,6 +76,17 @@ abstract class GenerateTask : AbstractBufExecTask() {
listOf("--template", it.absolutePath)
} ?: emptyList()

return importOptions + templateFileOption
val configOption =
if (noWorkspaceAndV1Syntax() || noWorkspaceAndNoProtobufGradlePlugin()) {
bufConfigFile.orNull?.let { listOf("--config", it.absolutePath) }
} else {
null
}.orEmpty()

return importOptions + templateFileOption + configOption
}

private fun noWorkspaceAndV1Syntax() = !hasWorkspace.get() && v1SyntaxOnly.get()

private fun noWorkspaceAndNoProtobufGradlePlugin() = !hasWorkspace.get() && !hasProtobufGradlePlugin.get()
}
Loading