Skip to content

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

Closed
@fabio-franco

Description

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

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