vscode-maven icon indicating copy to clipboard operation
vscode-maven copied to clipboard

Maven for Java cannot set settings.xml for different workspace

Open hzh-test opened this issue 2 years ago • 7 comments

As we know, the extension Language Support for Java(TM) by Red Hat can use with different java project and specify different settings.xml。So,I hope the Maven for Java extension can support this.

hzh-test avatar Oct 14 '22 04:10 hzh-test

It's set to machine scope for security reason. BTW, what's your use case?

Do you want to execute all maven commands with --settings path-to-local-settings.xml appended? If so, setting maven.executable.options can help. Or you can directly leverage .mvn/maven.config See https://maven.apache.org/configure.html#mvn-maven-config-file

Eskibear avatar Oct 19 '22 08:10 Eskibear

It's set to machine scope for security reason. BTW, what's your use case?

Do you want to execute all maven commands with --settings path-to-local-settings.xml appended? If so, setting maven.executable.options can help. Or you can directly leverage .mvn/maven.config See https://maven.apache.org/configure.html#mvn-maven-config-file

Hi Eskibear, I find maven.executable.options doesn't work even when I set --settings path-to-local-settings.xml, and when clicking maven install button, it still download dependencies following the default setting.xml, not mine. similar issue is raised in stackflow: Vscode doesn't respect the "maven.executable.options"

tianfudhe avatar Oct 26 '22 05:10 tianfudhe

Let's figure out whether it's related to VS Code Maven extension or Maven CLI itself.

I find maven.executable.options doesn't work even when I set --settings path-to-local-settings.xml

Did it send the expected command line (mvn .... --settings path-to-local-settings.xml) to the terminal? If so, then VS Code Maven extension had done its job correctly. In this case, it should be the same whether you run mvn command inside/outside vscode. Then culprit that I can think of might be either a malformed/invalid local-settings.xml or even malformed Maven CLI.

Eskibear avatar Oct 26 '22 14:10 Eskibear

Did it send the expected command line (mvn .... --settings path-to-local-settings.xml) to the terminal?

Thanks. I find maven extension works as expected, and my issue is not due to the maven-plugin. I figure this issue out that the command mvn ... -s local-settings.xml doesn't respect the local-settings.xml when there's already a settings.xml in the global path, i.e., in $MAVEN_HOME/conf/settings.xml.

When I delete the settings.xml in global path, mvn ... -s local-settings.xml works properly.

tianfudhe avatar Oct 26 '22 15:10 tianfudhe

I'm having a somewhat similar issue, but I want to use various setting.xml files at the base of different java repos.

Is there a way to access the absolute path of the java repo? Is there a variable I can reference in the maven.executable.options setting?

SolomonHD avatar Feb 25 '23 18:02 SolomonHD

this would be nice, also maybe if specifying a local repository settings.xml file (in the root) would take precendence over /.m2 settings as its not easy to change

jkone27 avatar Mar 13 '24 15:03 jkone27

After a quick search, I find a promising solution, using .mvn/maven.config: https://stackoverflow.com/a/48583079

The benefit is, this solution is not tied to vscode-maven, meaning that it's still working even if you are not using vscode.

Eskibear avatar Mar 14 '24 02:03 Eskibear