After fixing permission error on gradlew https://spacetech.dk/error-gradle-script-home-runner-work-gradlew-is-not-executable.html we ran into the next issue where the error message is a bit wage.
Error: Could not find or load main class org.gradle.wrapper.GradleWrapperMain Caused by: java.lang.ClassNotFoundException: org.gradle.wrapper.GradleWrapperMain Error: Gradle build failed: process exited with status 1
But taking a closer look at the CI pipeline action for Gradle there is not specified a version. So what version is taking? Why are we getting could not load main class org.gradle.wrapper.GradleWrapperMain.
- name: Build with Gradle uses: gradle/gradle-build-action@v2 with: arguments: build
Looking at the documentation at https://github.com/gradle/gradle-build-action#use-a-specific-gradle-version we see the default is ‘current’. Alright, so what’s the current version. Let us go one step further. At https://gradle.org/install/ we can locate the current version, as of this writing the current Gradle release is 7.4.2.
Next step is to figure out what version is my current gradle project actually running on. Take a look at \gradle\wrapper\gradle-wrapper.properties in your root folder.
distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists
Looking at the third line we can identify the Gradle version is in fact not version 7.4.2 but rather 6.8.
Now for the solution. We have identified the Gradle version should be 6.8. So let’s add that to the CI pipeline for the Gradle action by appending gradle-version as stated in the documentation. https://github.com/gradle/gradle-build-action#use-a-specific-gradle-version
- name: Build with Gradle uses: gradle/gradle-build-action@v2 with: arguments: build gradle-version: 6.8
Doing a new run with the change and the build goes through. We can see the provision Gradle 6.8 now and able to download.
Provision Gradle 6.8 Gradle distribution 6.8 not found in cache. Will download.
In the end we get a green build icon. Hurray!