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

Support Maven Wrapper #518

Open
rubensa opened this issue May 2, 2021 · 6 comments
Open

Support Maven Wrapper #518

rubensa opened this issue May 2, 2021 · 6 comments

Comments

@rubensa
Copy link

rubensa commented May 2, 2021

Nowadays Maven Wrapper looks like a the facto standard for including maven in your project so you do not need to install maven separately.
Tools like Spring Initializr scaffolds your project with it.

Dependency Analytics should support using the mvnw command out of the box if it is present in the project's folder.

Anyway I tried to set it up manually by setting maven.executable.path like:
"maven.executable.path": "${fileWorkspaceFolder}/mvnw"

But looks like ${fileWorkspaceFolder} variable replacement is not supported.

Then I tried:
"maven.executable.path": "/workspaces/project-folder/mvnw"

but got an error. This is the log:

 CMD :"/workspaces/project-folder/mvnw" --quiet clean -f "/workspaces/project-folder/pom.xml" && "/workspaces/project-folder/mvnw" --quiet org.apache.maven.plugins:maven-dependency-plugin:3.0.2:tree -f "/workspaces/project-folder/pom.xml" -DoutputFile="/workspaces/project-folder/target/dependencies.txt" -DoutputType=dot -DappendOutput=true
 STDOUT :  
 STDERR : /workspaces/project-folder/mvnw: 219: cannot open /vscode/vscode-server/bin/x64/3c4e3df9e89829dce27b7b5c24508306b151f30d/.mvn/wrapper/maven-wrapper.properties: No such file
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0Warning: Failed to create the file 
Warning: /vscode/vscode-server/bin/x64/3c4e3df9e89829dce27b7b5c24508306b151f30d
Warning: /.mvn/wrapper/maven-wrapper.jar: No such file or directory

  2 50710    2  1039    0     0  14842      0  0:00:03 --:--:--  0:00:03 14842
curl: (23) Failed writing body (0 != 1039)
Error: Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain

If I run those commands in the terminal they are executed without any problem and the dependencies.txtfile is generated in the target folder.

@rubensa
Copy link
Author

rubensa commented Apr 25, 2022

Related issue: #541

@rubensa
Copy link
Author

rubensa commented Apr 25, 2022

Also related to: #503

@funkyfisch
Copy link

Is there any progress in this? I can't imagine I am the only one using a maven wrapper for my projects instead of globally installing maven everytime

@rubensa
Copy link
Author

rubensa commented Dec 13, 2023

As a workaround I have created a custom mvnw wrapper file for mvnw itself that first changes directory to the workspace folder like (in the example /workspaces/project-folder):

#!/bin/sh
# Hack needed by redhat.fabric8-analytics extension that runs maven commands from vscode-server binary directory (not from workspace directory)
cd /workspaces/project-folder
/workspaces/project-folder/mvnw "$@"

and set the path to that wrapper in maven.executable.path setting.

NOTE: Also take into account that in latest version (0.7.3) maven.executable.path is not respected. See: #665

@harshrathod50
Copy link

I do not have Maven globally installed and I'm getting this error:

Command failed: mvn --version 'mvn' is not recognized as an internal or external command, operable program or batch file.

So as a workaround I added did this in settings.json:

{
  "redHatDependencyAnalytics.mvn.executable.path": "./mvnw"
}

But then I got this error:

Command failed: ./mvnw --version '.' is not recognized as an internal or external command, operable program or batch file.

So as a second workaround I did this:

{
  "redHatDependencyAnalytics.mvn.executable.path": "%USERPROFILE%\\.m2\\wrapper\\dists\\apache-maven-3.9.5-bin\\32db9c34\\apache-maven-3.9.5\\bin\\mvn"
}

Which worked well but now this doesn't work on linux, so as a third workaround I did this:

{
  "redHatDependencyAnalytics.mvn.executable.path": "$HOME/.m2/wrapper/dists/apache-maven-3.9.5-bin/32db9c34/apache-maven-3.9.5/bin/mvn"
}

Which worked well on linux but now this doesn't work on windows.

And then I gave up and removed RedHat Dependency Analytics extension. I just have two questions for the project maintainers:

  • Why there is no default support for Maven Wrapper?
  • Why are you making life difficult then it already is?

@rubensa
Copy link
Author

rubensa commented Jan 8, 2024

@harshrathod50 The problem here is that this extension does not run the mvn commands from the VSCode workspace folder (as most other extensions does and is needed by mvnw to find the .mvn folder).
As I said here I just created a bash wrapper for the mvnw that before calling the "real" mvnw command it sets the current working directory to the workspace folder and set that wraper as the redHatDependencyAnalytics.mvn.executable.path.

As most of my projects are run using Dev Containers I don't need a "compatible" wrapper for both bash and windows batch but you might try to create one like this.

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

No branches or pull requests

5 participants