Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go to - wrong - definition on protobuf generated classes #1852

Open
BruceWouaigne opened this issue Aug 21, 2021 · 3 comments
Open

Go to - wrong - definition on protobuf generated classes #1852

BruceWouaigne opened this issue Aug 21, 2021 · 3 comments

Comments

@BruceWouaigne
Copy link

Hi there, very first time for me posting an issue here so sorry in advance if this is not the right place.

So here's the thing, I'm using vscode 1.59.1 with Java language support v0.81.0 and I ran into something weird when using protobuf.

Let say there’s a proto definition file in my service generating a class named and namespaced exactly the same as one that is in a library that is part of my service deps.

Local definition file:

package bruce.proto.v1;

message Foo {
  string bar = 1;
  string baz = 2;
}

Imported library definition file:

package bruce.proto.v1;

message Foo {
  string bar = 1;
}

When writing var foo = Foo.newBuilder().setBaz(“qux”).build(); my service compiles successfully but vscode (as well as eclipse) complains that setBaz(String) is undefined for the type Foo.Builder.

image

When I cmd+click on Foo class it brings me to the generated class of the library instead of the one generated locally.

The classpath is set correctly and if I remove the library dependency the IDE doesn't complain anymore and Go To Definition works as expected.

If you want to see by yourself

$> git clone [email protected]:BruceWouaigne/test-java-lib.git && mvn -f test-java-lib install
$> git clone [email protected]:BruceWouaigne/test-java-app.git && mvn -f test-java-app compile

Then open test-java-app Java project in vscode or eclipse.

Cheers!

@BruceWouaigne
Copy link
Author

Nobody?!

@snjeza
Copy link
Contributor

snjeza commented Sep 2, 2021

@BruceWouaigne You can try to add the following plugin:

<plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.0.0</version>
        <executions>
            <execution>
                <id>addSource</id>
                <phase>generate-sources</phase>
                <goals>
                    <goal>add-source</goal>
                </goals>
                <configuration>
                    <sources>
                        <source>${project.basedir}/target/generated-sources/protobuf/java</source>
                    </sources>
                </configuration>
            </execution>
        </executions>
    </plugin>

to your test-java-app/pom.xml

See redhat-developer/vscode-java#2058 (comment)

@BruceWouaigne
Copy link
Author

Thanks @snjeza but that doesn't change a thing. Again my project build is passing but IDEs are getting confused.

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

No branches or pull requests

3 participants