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

java.configuration.maven.globalSettings doesn't seem to work #3303

Open
itaranto opened this issue Oct 22, 2024 · 12 comments
Open

java.configuration.maven.globalSettings doesn't seem to work #3303

itaranto opened this issue Oct 22, 2024 · 12 comments

Comments

@itaranto
Copy link

itaranto commented Oct 22, 2024

I have the following config inside /etc/maven/settings.xml (the global settings)

  <localRepository>${user.home}/.cache/maven/repository</localRepository>

But jdtls insists on creating ~/.m2/repository/.

I tried overriding Maven's globalSettings but they don't seem to work either. This are my java settings (Neovim):

        settings = {
          java = {
              -- ...
              maven = {
                userSettings = home_dir .. '/.config/maven/settings.xml',
                globalSettings = '/etc/maven/settings.xml',
              },
            },
          },
        },

I know the are correct because userSettings are actually being picked up (I have some other config there so I can confirm that).

I also tried setting localRepository inside ~/.config/maven/settings.xml and that works just fine (no ~/.m2/ directory being created).

@rgrunber
Copy link
Contributor

rgrunber commented Oct 25, 2024

Do you have a link to the client you are using ? Is it neovim with https://github.com/mfussenegger/nvim-jdtls or some other ? Are you sure your settings are being picked up from java.maven.userSettings or java.maven.globalSettings ? I ask because the proper (nested) settings should be java.configuration.maven.userSettings :

/**
* Preference key for Maven user settings.xml location.
*/
public static final String MAVEN_USER_SETTINGS_KEY = "java.configuration.maven.userSettings";
/**
* Preference key for Maven global settings.xml location.
*/
public static final String MAVEN_GLOBAL_SETTINGS_KEY = "java.configuration.maven.globalSettings";

I tried it out myself (in vscode-java), and it is working for me so maybe this is just some kind of configuration issue. I'd need to know more about the client though to see how they interact with the language server.

@itaranto
Copy link
Author

Do you have a link to the client you are using ? Is it neovim with https://github.com/mfussenegger/nvim-jdtls or some other ?

Yes, I'm using nvim-jdtls.

Are you sure your settings are being picked up from java.maven.userSettings or java.maven.globalSettings ?

I think you may be right here, I forgot that I had a shell alias too: alias mvn="mvn -s $HOME/.config/maven/settings.xml".

So it's most likely it's picking up my user settings from the alias and not from userSettings. So basically, neither userSettings nor globalSettings seem to be working (I tested by removing the alias).

I ask because the proper (nested) settings should be java.configuration.maven.userSettings :

These are the full settings:

        -- ...
        settings = {
          java = {
            configuration = {
              runtimes = {
                { name = 'JavaSE-11', path = '/usr/lib/jvm/java-11-openjdk/' },
                { name = 'JavaSE-17', path = '/usr/lib/jvm/java-17-openjdk/' },
                { name = 'JavaSE-21', path = '/usr/lib/jvm/java-21-openjdk/' },
              },
              maven = {
                userSettings = home_dir .. '/.config/maven/settings.xml',
                globalSettings = '/etc/maven/settings.xml',
              },
            },
          },
        },
        -- ...

As you can see it's java.configuration.maven.

Let me know if you need my full config, I'm not pasting it here since it can be quite long.

@itaranto
Copy link
Author

Also, like I mentioned in my first comment, it's weird that my global settings from /etc/maven/settings.xml are not being picked up automatically.

@itaranto
Copy link
Author

Well, I found something weirder.

It seems the .m2/repository dir gets created for new projects only. I mean, the ones that hasn't been complied already.

If I open a project that's already compiled, then the .m2/repository doesn't get created.

Excuse my terminology, I don't actually know if JDTLS actually complies the whole project or not. I'm also not a Java developer.

@itaranto
Copy link
Author

itaranto commented Oct 25, 2024

It seems the actual .jar files are being put in the correct location ~/.cache/maven/repository.

For example, when opening a specific project the first time, the ~/.m2/repository/ directory only contains a resolver-status.properties file. So maybe these projects I'm browsing may have some weird build setup, I don't know.

Maybe I could try testing this on a more "sane" Java repository, like an open-source project.

@snjeza
Copy link
Contributor

snjeza commented Oct 25, 2024

@itaranto could you show your /etc/maven/settings.xml ?

@itaranto
Copy link
Author

@itaranto could you show your /etc/maven/settings.xml ?

Yes, but it has nothing interesting. It's just the default plus the localRepository entry I mentioned at the beginning.

settings.txt

I renamed settings.xml to settings.txt because of Github...

@snjeza
Copy link
Contributor

snjeza commented Oct 25, 2024

Yes, but it has nothing interesting. It's just the default plus the localRepository entry I mentioned at the beginning

I have tried it in VS Code. It works fine.
Is /etc/maven/settings.xml accessible?

@itaranto
Copy link
Author

itaranto commented Oct 26, 2024

Yes, but it has nothing interesting. It's just the default plus the localRepository entry I mentioned at the beginning

I have tried it in VS Code. It works fine. Is /etc/maven/settings.xml accessible?

I'm sorry if I didn't clarified this before, but my Maven config works perfectly fine when running it from the CLI (mvn compile, mvn install, etc).

@snjeza
Copy link
Contributor

snjeza commented Oct 26, 2024

I'm sorry if I didn't clarified this before, but my Maven config works perfectly fine when running it from the CLI (mvn compile, mvn install, etc).

Could you run

$ mvn -X | grep "Reading global settings"

@itaranto
Copy link
Author

I'm sorry if I didn't clarified this before, but my Maven config works perfectly fine when running it from the CLI (mvn compile, mvn install, etc).

Could you run

$ mvn -X | grep "Reading global settings"
$ mvn -X | grep "Reading global settings"
[DEBUG] Reading global settings from /usr/share/maven/conf/settings.xml

/usr/share/maven/conf/settings.xml is a symlink to /etc/maven/settings.xml

$ ls -l /usr/share/maven/conf/settings.xml
lrwxrwxrwx. 1 root root 23 Mar  4  2024 /usr/share/maven/conf/settings.xml -> /etc/maven/settings.xml

Again, I didn't open this issue because of Maven not reading my settings, mvn reads my localRepository setting just fine.

@snjeza
Copy link
Contributor

snjeza commented Oct 27, 2024

Again, I didn't open this issue because of Maven not reading my settings, mvn reads my localRepository setting just fine

Could you try to reproduce the issue in VS Code?

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

No branches or pull requests

3 participants