IBM / codenet-minerva-code-analyzer

Java source code (and/or binary) to JSON based system dependency graph generator.
Apache License 2.0
2 stars 6 forks source link

Maven invocation requires mvn on PATH (env var) #64

Closed scottkurz closed 14 hours ago

scottkurz commented 1 week ago

The 'mvn' invocation assumes mvn/mvn.cmd is available from the PATH env var, even for a --no-build scenario (to copy deps).

More flexible would be to:

If that is too much, perhaps simply looking for a mvnw in the project root would be a shorter-term enhancement.

cherylking commented 1 week ago

Note that this is considered a "must fix" for GA. Please update with an outlook @rahlk. Thanks.

rahlk commented 1 week ago

Should be an easy fix. I'll make a 1.0.2 release where we look for mvnw wrapper similar to gradlew.

rahlk commented 1 week ago

Please note that there is a flag called --build-cmd to provide any arbitrary build command to build an application.

awisniew90 commented 4 days ago

Adding some feedback here... I tried out the mvnw function in the 1.0.2 release, but there are a few issues, particularly in BuildProject.java

private static final String MAVEN_CMD = System.getProperty("os.name").toLowerCase().contains("windows")
            ? (new File("mvnw.cmd").exists() ? "mvnw.cmd" : "mvn.cmd")
            : (new File("mvnw").exists() ? "mvnw" : "mvn");
  1. When checking for the existence of mvnw, we should be using a full path to the executable, preferably the path set by the new "-f" option in CA 1.0.3.
  2. When setting the MAVE_CMD variable, this should also be a full path.

Without this, the check for wrapper existence depends on being in a specific working directory, and the mvnw invocation fails regardless of which directory the command is run from since mvnw is treated as a system executable and not a local script.

rahlk commented 1 day ago

Hi @awisniew90, as per you suggestion, I have added the following patch in release 1.0.4:

    private static final String MAVEN_CMD = BuildProject.getMavenCommand();
    private static String getMavenCommand() {
        Boolean isWindows = System.getProperty("os.name").toLowerCase().contains("windows");
        String mvnCommand;
        if (isWindows) {
            mvnCommand = new File(projectRootPom, "mvnw.bat").exists() ? String.valueOf(new File(projectRootPom, "mvnw.bat")) : "mvn.bat";
        } else {
            mvnCommand = new File(projectRootPom, "mvnw").exists() ? String.valueOf(new File(projectRootPom, "mvnw")) : "mvn";
        }
        return mvnCommand;
    }

Verify compatibility and close issue if resolved.

awisniew90 commented 14 hours ago

Fix is working on CA 1.0.4 and properly using maven wrapper

2024-11-12T11:37:06.743833 [INFO]  Found pom.xml in the project directory. Using Maven to download dependencies.
2024-11-12T11:37:06.749503    [INFO]  Building the project using /Users/awisniew/Projects/WCA4J/multi-module-modresorts/mvnw.
2024-11-12T11:37:07.632651    [INFO]  [INFO] Scanning for projects...
2024-11-12T11:37:07.659549    [INFO]  [INFO] ------------------------------------------------------------------------
2024-11-12T11:37:07.659621    [INFO]  [INFO] Reactor Build Order:
2024-11-12T11:37:07.659652    [INFO]  [INFO] 
2024-11-12T11:37:07.659963    [INFO]  [INFO] ModResorts                                                         [war]
2024-11-12T11:37:07.660021    [INFO]  [INFO] modresorts-pom                                                     [pom]
awisniew90 commented 14 hours ago

@rahlk - I dont have access to close the issue, but please do so

rahlk commented 14 hours ago

Great! Thanks @awisniew90. Closing this issue.