coc-java icon indicating copy to clipboard operation
coc-java copied to clipboard

"import cannot be resolved" for gradle generated code

Open jeffkbkim opened this issue 4 years ago • 5 comments

When I open a gradle based project, jdtls loads successfully. However, I am seeing import errors from the server. More specifically, I see errors when importing generated code (created by gradle).

I can reproduce with an example project: https://github.com/apache/kafka

https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/clients/admin/KafkaAdminClient.java#L267-L272 will show "cannot be resolved" errors once the jdtls server starts.

The import org.apache.kafka.common.message cannot be resolved

org.apache.kafka.common.message in this project is generated by a gradle task, and is located under <project-root>/clients/src/generated/....

I see this behavior for both vscode and coc-java. is there a way to resolve this?

jeffkbkim avatar Jul 17 '21 05:07 jeffkbkim

Have to be fixed by jdt.ls.

chemzqm avatar Jul 20 '21 05:07 chemzqm

@chemzqm thanks for the response.

can you elaborate? is there anyway we can configure the client to add the generated directory?

jeffkbkim avatar Jul 20 '21 05:07 jeffkbkim

Maybe add that folder to your JAVA_PATH could work.

chemzqm avatar Jul 20 '21 05:07 chemzqm

afaik there's no JAVA_PATH env var. and this doesn't make sense to be added to JAVA_HOME nor PATH

jeffkbkim avatar Jul 20 '21 05:07 jeffkbkim

I've got same issuse , I've changed java.configuration.maven.userSettings,its maybe some jar download failed with default maven-setting.xml cause,this's my solution:try CocCommand java.clean.workspace, its work fine with me

AizenSosike avatar Jul 07 '22 02:07 AizenSosike

Use configuration java.configuration.maven.userSettings

chemzqm avatar Jan 29 '23 07:01 chemzqm