From 541ea06d877554c7266dd160eeab508f6be93f74 Mon Sep 17 00:00:00 2001 From: Vadym Yaroshchuk Date: Wed, 20 Nov 2024 19:51:19 +0100 Subject: [PATCH] chore: new api for gradle plugin --- Writerside/topics/CodeGen-Gradle.md | 59 +++++++++++++++++++---------- 1 file changed, 39 insertions(+), 20 deletions(-) diff --git a/Writerside/topics/CodeGen-Gradle.md b/Writerside/topics/CodeGen-Gradle.md index 447b185..94a2bea 100644 --- a/Writerside/topics/CodeGen-Gradle.md +++ b/Writerside/topics/CodeGen-Gradle.md @@ -23,31 +23,50 @@ The plugin is configured using the rrpc extension, allowing customization for .p ### Basic Example ```Kotlin rrpc { - targetSourceSet.set("commonMain") // Specify the source set for generated code - protosInput.set(listOf("src/main/proto")) // Define where to find .proto files - - kotlin { - output = "build/generated/kotlin" // Specify output directory - clientGeneration = true // Generate client stubs - serverGeneration = true // Generate server stubs - typeGeneration = true // Generate data types - metadataEnabled = true // Enable metadata generation - metadataScopeName = "MyScope" // Define metadata scope + // Configuring the input sources for .proto files + inputs { + // Adding a directory containing .proto files + directory(file("src/main/proto")) + + // Adding an artifact (e.g., JAR or KLIB) containing .proto files + artifact( + file = file("libs/protos.jar"), + includes = listOf("org/timemates/internal") + ) + + // Adding an external dependency artifact + artifact( + id = "com.example:proto-library:1.0.0", + excludes = listOf("org/timemates/internal"), + ) } -} -``` -### Configuration Properties + // Configuring plugins for code generation + plugins { + // enable kotlin generation + kotlin { + // Plugin-specific options + output = "build/generated/rrpc-kotlin" + clientGeneration = true + serverGeneration = true + } -#### `targetSourceSet` -- **Purpose:** Specifies the source set for code generation. -- **Why it's important:** Code generation tasks depend on this source set to correctly manage input and output directories for the build process. For instance, setting `commonMain` ensures that the generated files are included in the correct build phase. Especially useful for the custom source-set layouts. -- **Default:** `null` (falls back to default source sets like `commonMain` or `main`). + // External plugin configuration + external("com.example:typescript-generator:2.0.0") { + put("typescriptModule", "CommonJS") + put("outputDir", "build/generated/typescript") + } + } -```Kotlin -targetSourceSet.set("commonMain") + // Enabling package cycles if necessary + permitPackageCycles = true +} ``` -#### `protosInput` +The plugin automatically register its outputs for Kotlin (Multiplatform, Android, other named `main`) source sets for correct execution order. If you have +custom project, you can override its behavior by referencing to the outputs of `GenerateRRpcCodeTask`. + +### Configuration Properties +#### `inputs` - **Purpose**: Specifies the list of directories containing .proto files for generation. - **Default**: An empty list.