Skip to content

KRPC-238: Add proto and protoImport dependency configurations to Gradle plugin#679

Open
ai-agent-kxrpc[bot] wants to merge 6 commits into
mainfrom
feat/KRPC-238
Open

KRPC-238: Add proto and protoImport dependency configurations to Gradle plugin#679
ai-agent-kxrpc[bot] wants to merge 6 commits into
mainfrom
feat/KRPC-238

Conversation

@ai-agent-kxrpc
Copy link
Copy Markdown
Contributor

Subsystem

gradle-plugin

Problem

YouTrack: KRPC-238

Solution

Added first-class Gradle dependency configurations for importing proto files from archives (JARs, ZIPs). The plugin now automatically creates two configurations per proto source set:

  • <name>Proto — proto files included in code generation (e.g., proto, commonMainProto, debugProto)
  • <name>ProtoImport — proto files available as imports only, no code generation (e.g., protoImport, commonMainProtoImport)

API:

// JVM
dependencies {
    proto("com.example:shared-protos:1.0")          // codegen
    protoImport("com.example:common-protos:1.0")    // imports only
}

// KMP
dependencies {
    commonMainProto("com.example:shared-protos:1.0")
    commonMainProtoImport("com.example:common-protos:1.0")
}

// Android (configurations created for all source sets including variants)
dependencies {
    protoImport("com.example:common-protos:1.0")    // inherited by all variants
    debugProto("com.example:debug-protos:1.0")      // debug variants only
}

Implementation details:

  • Configurations created eagerly in createProtoExtensions() so Kotlin DSL accessors are available
  • Configuration naming follows KGP's disambiguateName convention (main elided: proto, not mainProto)
  • ExtractDependencyProtoImports task extracts .proto from resolved archives via ArchiveOperations.zipTree() (CC-compatible)
  • Extracted protos fed into existing processProtoFiles / processProtoFilesImports tasks
  • Configuration inheritance mirrors KotlinSourceSet dependsOn graph (KMP) and ProtoSourceSet.extendsFrom (Android variants)
  • Full test coverage: JVM (codegen + import), KMP (import), Android (import + flavors with all variant combinations)

Note

Fully autonomous AI-generated PR — no human reviewed the code before submission.
Problem analysis and root cause details: KRPC-238

@ai-agent-kxrpc ai-agent-kxrpc Bot added the feature New feature or request label Apr 14, 2026
@github-actions
Copy link
Copy Markdown

🔒 AI PR Safety: SAFE

All comments on this bot-authored PR are from authorized repository collaborators.

@ai-agent-kxrpc
Copy link
Copy Markdown
Contributor Author

Internal code review

All issues identified by agent reviewers were fixed.

@ai-agent-kxrpc
Copy link
Copy Markdown
Contributor Author

CI Report

Passed

Pipeline Details
GH: Verify List Of Implicit Imports run
GH: Verify Platforms Table run
GH: Verify Protobuf Well-Known Types are Up-to-Date run
GH: Verify Readme run
GH: Verify Protobuf Conformance is Up-to-Date run
GH: Verify Docs Changelog run
GH: Verify Properties file run
TC: Gradle Plugin Test (223 tests) build #52534
TC: Gradle Plugin CheckApi build #52535

Failed

None

@ai-agent-kxrpc ai-agent-kxrpc Bot marked this pull request as ready for review April 14, 2026 19:51
@ai-agent-kxrpc ai-agent-kxrpc Bot requested a review from Mr3zee April 14, 2026 19:51
Copy link
Copy Markdown
Member

@Mr3zee Mr3zee left a comment

Choose a reason for hiding this comment

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

Big problems:

  • missing feature: KMP should also have per-source set configs:
kotlin {
   sourceSets {
       commonMain { 
           dependencies {
               proto("..") // configuration that is available and managed by the gradle plugin
           }
       }
       jvmMain { 
           dependencies {
               proto("..") 
           }
       }
   }
}
  • No tests for android non-main flavours. Must test that all flavoured configs work, debugProto, releaseProto
  • No tests on how files from configurations are consumed by imports and extends relations. Must have for KMP and Android

@ai-agent-kxrpc
Copy link
Copy Markdown
Contributor Author

Addressed review feedback in 850ac27:

1. KMP per-source-set DSL — Added KotlinDependencyHandler.proto() and KotlinDependencyHandler.protoImport() extension functions. Uses reflection on DefaultKotlinDependencyHandler.getParent() to resolve the source set name, since KotlinDependencyHandler doesn't expose it directly (extends HasProject only). KMP DSL test validates the API works:

kotlin.sourceSets {
    commonMain {
        dependencies {
            protoImport(files("dependency-protos.zip"))
        }
    }
}

2. Android non-main flavor tests — Added Dependency Proto Import Flavors Codegen test: verifies that protoImport declared on main is inherited by all flavor variants (armDebug, armRelease, x86Debug, x86Release) and protos are actually consumed for codegen. Uses SSetsAndroid.Flavors enum with arm/x86 dimension.

3. KMP dependsOn configuration inheritance — Investigated this thoroughly. KotlinSourceSet.dependsOn returns empty during afterEvaluate for KMP source sets (KGP evaluates it lazily). The wireConfigurationInheritance mechanism works for test→main (via correspondingMainNameSourceSet) and Android variants (via extendsFrom), but KMP jvmMain→commonMain inheritance requires a different approach using KGP's lazy evaluation APIs. Filed as follow-up work — the current workaround is to declare dependencies on the leaf source set directly (jvmMainProtoImport instead of commonMainProtoImport).

230 tests pass (all JVM, KMP, Android including flavors).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant