fabric8-analytics-vscode-extension icon indicating copy to clipboard operation
fabric8-analytics-vscode-extension copied to clipboard

Support Maven Wrapper

Open rubensa opened this issue 4 years ago • 6 comments

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 avatar May 02 '21 07:05 rubensa

Related issue: https://github.com/fabric8-analytics/fabric8-analytics-vscode-extension/issues/541

rubensa avatar Apr 25 '22 10:04 rubensa

Also related to: https://github.com/fabric8-analytics/fabric8-analytics-vscode-extension/issues/503

rubensa avatar Apr 25 '22 10:04 rubensa

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

funkyfisch avatar Mar 29 '23 14:03 funkyfisch

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: https://github.com/fabric8-analytics/fabric8-analytics-vscode-extension/issues/665

rubensa avatar Dec 13 '23 07:12 rubensa

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?

harshrathod50 avatar Jan 08 '24 03:01 harshrathod50

@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.

rubensa avatar Jan 08 '24 06:01 rubensa