You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While I'm fully aware that Android projects are unsupported, manually crafting .classpath files provide quite satisfying results - with the caveat that they don't support env vars, so you have to hardcode the path to your Android SDK.
For example, with a classpath that looks like:
I'm able, after indexing, to get completion for my project's classes, but also Android's.
Libraries need a little more work, but I don't mind doing everything manually, as both the platform version and libraries don't change often.
The problem is that vscode-java notices that this is a gradle project, and will overwrite.
I have to rewrite the .classpath with my version every time I reopen vscode.
I'd like to have a setting to tell the plugin never to overwrite .classpath on its own.
Environment
Operating System: macOS & Windows
JDK version: 1.8
Visual Studio Code version: 1.15.1
Java extension version: Latest as of writing
Steps To Reproduce
Open a
Patch the .classpath yourself. Make sure you back it up somewhere else
Restart vscode
Current Result
.classpath was overwritten with an empty one
Expected Result
.classpath should have not been overwritten
Additional Informations
I tried setting " "java.configuration.updateBuildConfiguration": "disabled" ", but that does not help
Reacted by Paul Grime, Denis Davydov, Artem and Carlos Knippschild
For now, I can't seem to get this to work. The eclipse plugin throws a null pointer when defining a "file" section, and does not recognize any of the configurations. I also tried a gradle android plugin, which throws an NPE
Note that I'm running the beta Android tools, which work really differently than the old ones. I'm not surprised that it breaks.
I'll try removing write permissions on .classpath. It should work around my problem for the time being.
@fbricon Sorry for the late response, I was away for a few weeks.
Buildship always overrides the classpath when a project is refreshed. However, the content of the classpath file can be customized in the eclipse.classpath.file.whenMerged { ... } block. Here are a few examples.
I tried adding a eclipse.classpath.file section again, and this time the NPE is gone. I'm not sure what happened back then.
Anyway, I'll override everything I need in the classpath in the gradle file.
While I still think that it would be handy to force vscode-java to use the .classpath I provide and ignore Gradle, this solution works for me! #286 mentions that Gradle overwrites the classpath on build, but my Gradle CLI builds don't do that and make their own classpath (Android tools are quite different from standard Gradle stuff).
I also don't need the extension to build my project, I "just" need it to provide code completion.
Discussion might be more appropriate on that issue, but as the build.gradle eclipse plugin solution works for me, I think resources are best spent elsewhere.
Anybody who really wants to prevent .classpath to be overwritten can also use their native OS' features to do so. It worked for me.
I was experiencing an issue similar to this and I managed to work around the problem. I had used Spring to generate a basic Rest API app and it created both Maven and Gradle constructs. I am partial to Maven so I updated pom.xml to add some dependencies. Everything seemed fine but, not sure what happened, without warning my local classpath-based compiles stopped working. The dependencies I had added to the classpath had disappeared. In fact the classpath no longer had any Maven references at all, just Gradle. "mvn, clean package" worked at all times.
I searched extensively and could not find a reason this would have occurred. I finally found these two settings for Red Hat Developer and set them as follows in my workspace settings.
This is a huge frustration for me as vscode-java consistently generates the wrong .classpath settings for my projects (Minecraft mods) and there's no way to stop it from doing so that I can find. Unlike @bigtfromaz I cannot disable Gradle as it's a core part of my workflow.
What are the chances of seeing movement on this issue?
Activity
fbricon commentedon Aug 24, 2017
It seems Buildship always overwrites .classpath files on Gradle project import. @donat is there any way (API) to prevent that?
fbricon commentedon Aug 24, 2017
@abarisain have you tried getting gradle to generate a customized eclipse .classpath? See https://docs.gradle.org/4.1/dsl/org.gradle.plugins.ide.eclipse.model.EclipseClasspath.html
abarisain commentedon Aug 29, 2017
Hello, thanks for the fast answer!
I've tried to use a Gradle plugin that generates a classpath by reading the Android project, but it fails on some of my projects.
I did not think of using the plugin you've linked. I'll give it a shot, thanks!
fbricon commentedon Aug 29, 2017
Please comment your findings here, that might help other people
abarisain commentedon Aug 30, 2017
For now, I can't seem to get this to work. The eclipse plugin throws a null pointer when defining a "file" section, and does not recognize any of the configurations. I also tried a gradle android plugin, which throws an NPE
Note that I'm running the beta Android tools, which work really differently than the old ones. I'm not surprised that it breaks.
I'll try removing write permissions on .classpath. It should work around my problem for the time being.
Thanks for the support!
donat commentedon Sep 5, 2017
@fbricon Sorry for the late response, I was away for a few weeks.
Buildship always overrides the classpath when a project is refreshed. However, the content of the classpath file can be customized in the
eclipse.classpath.file.whenMerged { ... }block. Here are a few examples.abarisain commentedon Sep 5, 2017
I tried adding a eclipse.classpath.file section again, and this time the NPE is gone. I'm not sure what happened back then.
Anyway, I'll override everything I need in the classpath in the gradle file.
While I still think that it would be handy to force vscode-java to use the .classpath I provide and ignore Gradle, this solution works for me!
#286 mentions that Gradle overwrites the classpath on build, but my Gradle CLI builds don't do that and make their own classpath (Android tools are quite different from standard Gradle stuff).
I also don't need the extension to build my project, I "just" need it to provide code completion.
Discussion might be more appropriate on that issue, but as the build.gradle eclipse plugin solution works for me, I think resources are best spent elsewhere.
Anybody who really wants to prevent .classpath to be overwritten can also use their native OS' features to do so. It worked for me.
I believe this issue can be closed.
Thanks.
bigtfromaz commentedon Jul 23, 2018
I was experiencing an issue similar to this and I managed to work around the problem. I had used Spring to generate a basic Rest API app and it created both Maven and Gradle constructs. I am partial to Maven so I updated pom.xml to add some dependencies. Everything seemed fine but, not sure what happened, without warning my local classpath-based compiles stopped working. The dependencies I had added to the classpath had disappeared. In fact the classpath no longer had any Maven references at all, just Gradle. "mvn, clean package" worked at all times.
I searched extensively and could not find a reason this would have occurred. I finally found these two settings for Red Hat Developer and set them as follows in my workspace settings.
Made an innocuous change to the pom.xml file, saved it, and the build returned to normal.
It would appear that the two features are replacing the classpath.
glektarssza commentedon Mar 10, 2026
This is a huge frustration for me as
vscode-javaconsistently generates the wrong.classpathsettings for my projects (Minecraft mods) and there's no way to stop it from doing so that I can find. Unlike @bigtfromaz I cannot disable Gradle as it's a core part of my workflow.What are the chances of seeing movement on this issue?