square / square/wire

Warn if generating a `.java` or `.kt` file when an equivalent `.class` file already exists

Open
#2,008 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Kotlin
Stars
4.4k
Forks
627
Avg merge
3d 15m
Merged PRs (30d)
20

Description

We’ve seen problems where projects use sourcePath when they want protoPath, and end up getting multiple generated files for the same .proto input. Often this is benign, but it will cause problems if one generator is .java and the other is .kt.

When generating say, com/example/Foo.java, we should check to see if a file com/example/Foo.class exists on either the sourcePath or the protoPath. If it does, we should emit a warning:

  Warning: generated files duplicate existing classes.
     com.example.Foo duplicates a class in com/example/foo-1.0.0.jar
     com.bananas.Banana duplicates a class in com/bananas/banana-2.0.0.jar
  Use protoPath {...} rather than sourcePath {...} to not generate classes for these protos.
  Or use `wire_package` to avoid collisions with protoc-generated classes.
  Or use `checkForDuplicates=false` to suppress this warning.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue does not name specific files or tests; start by locating the code-generation path that handles Java and Kotlin output and the sourcePath/protoPath options. Use the duplicate-file examples and warning text as acceptance criteria, including the checkForDuplicates suppression option and the suggested remedies.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.