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

lemminx-maven completely ignore local settings #196

Closed
glhez opened this issue Jan 28, 2021 · 7 comments
Closed

lemminx-maven completely ignore local settings #196

glhez opened this issue Jan 28, 2021 · 7 comments
Labels
bug Something isn't working

Comments

@glhez
Copy link

glhez commented Jan 28, 2021

Hello,

I am using version 1.17.0.20201203-1258 (as told by the Window > Help for POM Editor using LemMinX language server / org.eclipse.m2e.lemminx.feature.feature.group).

Because I override the default .m2 local repository and put a file instead (eg: echo "FILE" >"${USERPROFILE}/.m2/repository"), Lemminx Maven is failing because it uses the default repository which I don't want:

Non-resolvable import POM: Could not transfer artifact org.junit:junit-bom:pom:5.7.0 from/to central-mirror (https://jcenter.bintray.com/): %USERPROFILE%\.m2\repository\org\junit\junit-bom\5.7.0\aether-738fca6a-b95a-43a5-90dc-8ccff46afeb0-junit-bom-5.7.0.pom-in-progress (Le chemin d’accès spécifié est introuvable)

To ensure that no one tries to write in %USERPROFILE%\.m2\repository, I created a file instead of a directory - hence the error.

The problem however is that Lemminx don't take into account the default settings.xml which starts with:

<?xml version="1.0" encoding="utf-8" ?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0
                      http://maven.apache.org/xsd/settings-1.1.0.xsd">
  <localRepository>E:\apps\data\maven-local</localRepository>
   ...
</settings>

The settings are configured to default in the Eclipse Maven preferences and I've got a lot of dubious warnings:

Plugin could not be resolved. Ensure the plugin's groupId, artifactId and version are present.

Additional information: Plugin org.apache.maven.plugins:maven-clean-plugin:3.1.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:3.1.0

I think those are related: the Language Server is explicitly ignoring the settings.xml for whatever reason.

The issue #42 was closed without much fixes.

A m2.conf as stated in the #42 could be fine, but I don't see why I would have to do that : my settings is in the default location, and it is not even being read otherwise it would have read the repo path...

Is there a way for me to force it to use the good settings/localRepository ?

How can I diagnose ? (the Language Server logs does not seems to provide hints)

@mickaelistria
Copy link
Contributor

I added some bug to debug such cases to https://github.com/eclipse-m2e/m2e-core/blob/master/org.eclipse.m2e.editor.lemminx/HOWTO-DEV.md#how-can-i-debug-the-lemminx-maven-instance-and-m2e-at-the-same-time . Please try that. The piece of code you'd like to place your breakpoint is MavenLemminxExtension#initMavenRequest.

@glhez
Copy link
Author

glhez commented Feb 1, 2021

I like the sentence "I added some bug to debug" :)

Some remarks (I may do a PR to update the HOWTO-DEV.md later if needed):

  1. my default Eclipse installation did not have the Run as Eclipse installation. I had to use a RCP Eclipse.
  2. I fail to understand how to run debug mode. I've put -Dorg.eclipse.wildwebdeveloper.xml.internal.debugPort=20132 to the Java "VM Args", and as well as the Program arg, under as in -vmargs -Dorg.eclipse.wildwebdeveloper.xml.internal.debugPort=20132. Neither worked.
  3. How can I tell which Lemminx Maven version I'm under? As far as I understand, the tag reference a version 0.2.0 and from the date, I know I should have it if it was integrated into Eclipse 2020.12. I looked in the Plugins but could not find the version.

Since I could not start in debug mode, I could not check the problem.

In the JSON exchange between server and Eclipse, I can see:

Non-resolvable import POM: Could not transfer artifact org.junit:junit-bom:pom:5.7.0 from/to central-mirror (INTERNAL_REPOSITORY): %USERPROFILE%.m2\repository\org\junit\junit-bom\5.7.0\aether-024b5162-ebbb-462f-ba99-89af31b6d1f0-junit-bom-5.7.0.pom-in-progress (The system cannot find the path specified)
Non-resolvable import POM: Could not transfer artifact com.fasterxml.jackson:jackson-bom:pom:2.12.1 from/to central-mirror (INTERNAL_REPOSITORY): %USERPROFILE%.m2\repository\com\fasterxml\jackson\jackson-bom\2.12.1\aether-b2ca945d-f74a-453c-9b63-6d7897a94c75-jackson-bom-2.12.1.pom-in-progress (The system cannot find the path specified)

This, then, give a lot of error due to missing version - which is probably due to the bom not being available.

I also looked at another pom, which does not a reference a dependency under a bom: no problem there. I suppose there is something done only in case of bom, which trigger the download.

Without debug information, is there a way to produce debug stacktrace as in mvn -e ?

@mickaelistria
Copy link
Contributor

I've put -Dorg.eclipse.wildwebdeveloper.xml.internal.debugPort=20132 to the Java "VM Args", and as well as the Program arg, under as in -vmargs -Dorg.eclipse.wildwebdeveloper.xml.internal.debugPort=20132. Neither worked.

My bad, the property is org.eclipse.wildwebdeveloper.xml.internal.XMLLanguageServer.debugPort. I'll update the doc accordingly.
I also added some extra hints in the HOWTO-DEV.md doc according to your feedback.

@glhez
Copy link
Author

glhez commented Feb 1, 2021

Thanks.

The method you mentioned is the good one, however, you can't debug it without resorting to tricks: it is called before the debugger session start (if I close all pom.xml, then the LanguageServer close, ... and well, you can't debug something that is closed). This could be a good idea to also a property to suspend the vm (I've found the commit eclipse-wildwebdeveloper/wildwebdeveloper@0a5abb2#diff-4456e8cd4d3f9f5efa224593afe476fd9ea7c4e4d1281fcdd3f53f7f922fff10 )

The best is to put a breakpoint here: org.eclipse.lemminx.extensions.maven.MavenDiagnosticParticipant.doDiagnostics

And when it goes into project cache, to remove (using Eclipse) the mavenSession so that it reinitialize again (see trace below):

  • MavenLemminxExtension.initMavenRequest(PlexusContainer, JsonObject) line: 189
  • MavenLemminxExtension.initialize() line: 132
  • MavenLemminxExtension.getProjectCache() line: 283
  • MavenDiagnosticParticipant.doDiagnostics(DOMDocument, List, XMLValidationSettings, CancelChecker) line: 49

Then I can see what's the problem.

In fact, the maven settings is read from the configured path: https://github.com/eclipse/lemminx-maven/blob/master/lemminx-maven/src/main/java/org/eclipse/lemminx/extensions/maven/MavenLemminxExtension.java#L178

... but the local repository is forced to a default value in line 184 : https://github.com/eclipse/lemminx-maven/blob/master/lemminx-maven/src/main/java/org/eclipse/lemminx/extensions/maven/MavenLemminxExtension.java#L184

This can be seen by putting a breakpoint on that line, and going into setLocalRepositoryPath: the actual path is the expected one! If I force the parameter localRepositoryPath to the this.localRepositoryPath (eg: so that the setter does nothing), my pom.xml is no longer plagued with errors.

As I don't understand the login behind the line 185 to 196, I can only tell that the value should be set only if there is none already set: the settings is always read (once) in any case. I suppose the repo.maven.local is a maven option to override the one defined in settings, and that Lemmix Maven is simply handling it..

I also don't know how this behave if I change the settings.xml after the "project cache" is set.

I'll try to do a PR if I have time this week: I'll use a NTFS Junction from .m2/repository to my actual repository in the mean time.
And strangely enough, I did not have that problem on another computer, so my analysis may only partially apply.

@mickaelistria mickaelistria added the bug Something isn't working label Feb 2, 2021
@mickaelistria
Copy link
Contributor

Thanks a lot for the detailed analysis!
The line that sets M2 repo to default should skipped if the settings already configured the local repo.
L185-L196 are meant to allow consumer to override the location of the Maven repo in different ways: if the LS is started with -Dmaven.repo.local=... VM option, or if the initializationOptions (typically provided by the IDE) do configure the local repository. Those are supposed to override the user settings; however, as you realized, the default value shouldn't override the user settings and it currently does, causing this bug.
I'll eagerly review your PR. We plan a release of LemMinX-Maven soon, I hope it will fit in!

@glhez
Copy link
Author

glhez commented Feb 5, 2021

Here the PR. Quite simple but in all honestly, I only have the problem at work, on a citrix desktop.

Either the "aether-b2ca945d-f74a-453c-9b63-6d7897a94c75-jackson-bom-2.12.1.pom-in-progress" is not downloaded on my computer, either there is something else.

I do think, all thing considered, that it is an error to force the localRepoPath to some default when you already read the settings and those override the default value.

@mickaelistria
Copy link
Contributor

I do think, all thing considered, that it is an error to force the localRepoPath to some default when you already read the settings and those override the default value.

Yes it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants