Vscode-java: Add the java.configuration.maven.globalSettings property

Created on 4 Apr 2020  Â·  23Comments  Â·  Source: redhat-developer/vscode-java

I'm very close to make the switch to VSCode from Eclipse, this is the last hurdle, but one I can't walk around. Please help.

The Problem: A working Maven project that builds fine with command line mvn will have many errors in pom once loaded in VS code. POM errors result in classes / types in dependency libraries not resolved in the editor.

Note: This seems to happen only within a corporate network using our own internal central repo server (like "https://internal.myfirm.com/repository/maven/"). Same code works at home, though I don't use any customized maven setting files like those at work.

Screenshot of the project error here:

vscode-err-mytest1

My guess is as a result of the error, no .classpath file is generated, and no dependencies are shown on the project tree on the left panel.

What I don't understand is why would VSCode complain about connecting to the public Maven central repo while my maven settings point to our own repo server?

If I replace both settings.xml with standard plain setting files, it pulls dependencies from the public maven central https://repo.maven.apache.org/maven2 and works just fine. Obviously I cannot do that in practice as I'm required to use corporate maven repo.

Note:

  • mvn command works fine standalone, recognizing the customized maven setting files, downloading dependencies from the internal repo.
  • No override of any maven settings is put into VScode
  • Environment variables are set on the machine:
    M2=C:devmaven3.3.9bin
    M2_HOME=C:devmaven3.3.9

Environment
OS: Windows10 build 1809, 64-bit
VSCode Version: 1.43.2
Electron: 7.1.11
Chrome: 78.0.3904.130
Node.js: 12.8.1
V8: 7.8.279.23-electron.0

Reference Files

Most helpful comment

Yeah this bit me real bad! Please make a java.configuration.maven.globalSettings property available and have it default to ${M2_HOME}/conf/settings.xml

All 23 comments

@snjeza Thanks. I don't know how it was generated but it's an enterprise internal cert (the name I used above is masked for obvious reasons). You think it has something to do with the cert?

You think it has something to do with the cert.

Does the issue happen in Eclipse?
Do you use a proxy?

@snjeza It works fine with Eclipse, no proxy used in Eclipse, the repo server is within the corp network. Eclipse's Maven setting points to the exact same setttings.xml files as installed on my machine.

@alantango Could you send your VS Code settings.json and Maven settings.xml path?

@snjeza Here:
C:Usersuser-nameAppDataRoamingCodeUsersettings.json
C:Usersuser-name.m2setttings.xml

Here is the entire settings.json:

{
    "workbench.startupEditor": "newUntitledFile",
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\cmd.exe",
    "window.zoomLevel": 0,
    "editor.suggestSelection": "first",
    "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
    "java.configuration.checkProjectSettingsExclusions": false,
    "java.configuration.maven.userSettings": "",
    "java.errors.incompleteClasspath.severity": "ignore",
    "breadcrumbs.enabled": false,
    "maven.executable.preferMavenWrapper": true,
    "http.proxyStrictSSL": true,
    "java.dependency.packagePresentation": "hierarchical",
    "maven.pomfile.autoUpdateEffectivePOM": true,
    "maven.terminal.useJavaHome": true,
    "telemetry.enableCrashReporter": false,
    "telemetry.enableTelemetry": false,
    "workbench.settings.enableNaturalLanguageSearch": false,
    "extensions.autoUpdate": false,
    "workbench.enableExperiments": false
}

@alantango could you try to add the following VS Code settings:

"java.configuration.maven.userSettings": "C:\\Users\\user-name.m2\\setttings.xml",

or

"java.configuration.maven.userSettings": "C:\\Users\\user-name\\.m2\\settings.xml",

@snjeza Tried both and problem remains the same.

Btw I also tried a popular suggestion of command "Java: clean the Java Language server workspace" -> Restart and clean, with or without above changes, no effect.

Could you show the next Eclipse Preferences:
General>Network Connections
Maven>User Settings

@alantango which version of Eclipse are you using?

Eclipse Version: Oxygen.3a Release (4.7.3a)
Build id: 20180405-1200

eclipse-settings

Could you show the General>Network Connections Eclipse Preferences?

VS Code doesn't use global maven settings.
Could you try append your global settings to your user settings?

@snjeza Oh that's interesting...didn't know that. Anyways just tried, problem remains. I made sure mvn command standalone still works.

Anyways just tried, problem remains. I made sure mvn command standalone still works.

@alantango could you try the following in Eclipse:

  • append your global settings to your user settings
  • remove the global settings preference

Could you also check Eclipse IDE 2020‑03?

@snjeza Current Eclipse works with merged global setting files. But vscode still won't work. Don't plan to change to Eclipse 2020-03.

@snjeza Current Eclipse works with merged global setting files. But vscode still won't work. Don't plan to change to Eclipse 2020-03.

@alantango Could you send your VS Code log when using merged global settings in VS Code?

Could you send your VS Code log when using merged global settings in VS Code?
See attached. Same errors seen in my original post's attached log.
vscode-jdt2.log

@alantango could you send the output of the following command:

type C:\Users\user-x\.m2\setttings.xml 

You have three 't' in settings.xml

@snjeza Ahh that was it. I corrected and file name and it worked, then I removed the setting altogether and it worked as well. Looking at the thread history, that wrong file name '_setttings.xml_' was added BEFORE I merged the global settings file. It can either be empty or put in with a correct file name.

Thank you very much!

So the key is what you said earlier: VS Code doesn't use global maven settings. I would strongly suggest making that statement prominently clear on the README of this extension.

I believe this is also the solution to #1232.

@fbricon should we add the java.configuration.maven.globalSettings property?

@snjeza , one more voice here, but:

should we add the java.configuration.maven.globalSettings property?

yes. A colleague and I spent about 3 hours digging around in all the wrong places to finally discover this comment chain. It would be best to support globalSettings as its a very highly used maven idiom. But if you dont, it would be nice to put that somewhere in the documentation.

Yeah this bit me real bad! Please make a java.configuration.maven.globalSettings property available and have it default to ${M2_HOME}/conf/settings.xml

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jcjolley picture jcjolley  Â·  3Comments

ronniehicks picture ronniehicks  Â·  3Comments

danielcalvogonzalez picture danielcalvogonzalez  Â·  3Comments

sfariaNG picture sfariaNG  Â·  3Comments

ulongx picture ulongx  Â·  4Comments