Skip to content

Code analyzer fails when gradle wrapper is in the project (gradlew) #88

Closed

Description

@fabio-franco

Describe the bug

Code analyzer fails to execute when a gradle wrapper (gradlew) is defined in the project. This is the error:

/Users/<user>/.sdkman/candidates/java/current/bin/java -jar ~/Downloads/codeanalyzer-1.0.8.jar -i /Users/<user>/Development/git/wca4j/svt/gradle-java-ear -o /Users/<user>/.wca/codeAnalyzer/gradle-java-ear --project-root-path /Users/<user>/Development/git/wca4j/svt/gradle-java-ear --no-build -a 2 -v
2025-01-13T12:45:02.961717	[INFO]	Found build.gradle or build.gradle.kts in the project directory. Using gradle to download dependencies.
java.lang.RuntimeException: java.lang.IllegalStateException: Could not find a valid Gradle command. I did not find gradlew in the project directory or in the system PATH.
	at com.ibm.cldk.CodeAnalyzer.run(CodeAnalyzer.java:103)
	at picocli.CommandLine.executeUserObject(CommandLine.java:1767)
	at picocli.CommandLine.access$900(CommandLine.java:145)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2139)
	at picocli.CommandLine$RunLast.handle(CommandLine.java:2106)
	at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:1973)
	at picocli.CommandLine.execute(CommandLine.java:1902)
	at com.ibm.cldk.CodeAnalyzer.main(CodeAnalyzer.java:92)
Caused by: java.lang.IllegalStateException: Could not find a valid Gradle command. I did not find gradlew in the project directory or in the system PATH.
	at com.ibm.cldk.utils.BuildProject.downloadLibraryDependencies(BuildProject.java:243)
	at com.ibm.cldk.CodeAnalyzer.analyze(CodeAnalyzer.java:121)
	at com.ibm.cldk.CodeAnalyzer.run(CodeAnalyzer.java:101)
	... 7 more

The workaround is to remove (or move) the gradlew from the project, then code analyzer works fine.

Steps To Reproduce

Steps to reproduce the behavior:
EDIT
For https://github.com/hammingweight/gradle-java-ear we'll need to create a wrapper.

  1. Clone https://github.com/hammingweight/gradle-java-ear with git clone https://github.com/hammingweight/gradle-java-ear
  2. Create a gradle wrapper inside the project using gradle wrapper.
  3. Then replace compile by implementation and comment out the testCompile inside the build.gradle files under /ejb and /war folders.
  4. After that, using java 11 and gradle 7.3.3, generate a gradlew by using gradle wrapper in the project root folder.
  5. Execute code analyzer for the project, i.e.:
/Users/<user>/.sdkman/candidates/java/current/bin/java -jar ~/Downloads/codeanalyzer-1.0.8.jar -i /Users/<user>/Development/git/wca4j/svt/gradle-java-ear -o /Users/<user>/.wca/codeAnalyzer/gradle-java-ear --project-root-path /Users/<user>/Development/git/wca4j/svt/gradle-java-ear --no-build -a 2 -v

See the error indicated above.

Observed behavior

It should use the wrapper without issues.

Expected behavior

No errors. Also, since the wrapper is used, it should not complain in case gradle is not installed in the machine.

Environment (please complete the following information):

  • OS: macOS 15.1.1
  • Version of Java: 11
  • Version of Gradle: 7.3.3

Activity

  1. fabio-franco commented on Jan 13, 2025

    @fabio-franco
    CollaboratorAuthor

    In #87 it mentioned a similar behavior on maven, maybe both can be solved similarly.

    Apart from that, consider updating the message "Could not find a valid Gradle command. I did not find gradlew in the project directory or in the system PATH." because there is a gradlew in the project and the gradle is in the PATH. Also, "I did not find..." seems awkward from a cli message. Maybe something like "It was not possible to find ..."?

  2. self-assigned this
    on Jan 15, 2025
  3. rahlk commented on Jan 15, 2025

    @rahlk
    Collaborator

    Hi @fabio-franco, could you clarify that this error is occurring in https://github.com/hammingweight/gradle-java-ear?

    I am not able to see a wrapper called gradlew in this project. Could you verify if your system has gradle in PATH, if this project neither has a gradlew not gradle in the system path for a gradle project, then this exception is the expected behavior.

    Image

    Regardless, PR #92 should have fixed this issue now.

  4. rahlk commented on Jan 15, 2025

    @rahlk
    Collaborator

    Apart from that, consider updating the message "Could not find a valid Gradle command. I did not find gradlew in the project directory or in the system PATH." because there is a gradlew in the project and the gradle is in the PATH. Also, "I did not find..." seems awkward from a cli message. Maybe something like "It was not possible to find ..."?

    "I did not find a ..." -> "Could not find a ..." in the latest PR #92

  5. fabio-franco commented on Jan 16, 2025

    @fabio-franco
    CollaboratorAuthor

    Hi Rahul, I've described how to generate the wrapper in the Steps to reproduce the issue:

    Steps To Reproduce
    Steps to reproduce the behavior:

    This might be reproduced in any gradle project with a wrapper. Anyway, you can clone the project from https://github.com/hammingweight/gradle-java-ear, and then replace compile by implementation and comment out the testCompile inside the build.gradle files under /ejb and /war folders.
    After that, using java 11 and gradle 7.3.3, generate a gradlew by using gradle wrapper in the project root folder.

    Also, note that I mentioned that you can reproduce this issue in any project, don't need to be this one specifically. The more important piece is to have a wrapper.

  6. rahlk commented on Jan 16, 2025

    @rahlk
    Collaborator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions