Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why when I use github actions CI for a gradle project I face "./gradlew: Permission denied" error?

I have a very simple gradle project and when I setup GitHub Actions CI I face this error:

Run ./gradlew clean dependencies
  ./gradlew clean dependencies
  shell: /bin/bash -e {0}
  env:
    JAVA_HOME: /opt/hostedtoolcache/Java/8.0.222/x64
    JAVA_HOME_8.0.222_x64: /opt/hostedtoolcache/Java/8.0.222/x64
/home/runner/work/_temp/8f29e484-fbb4-4e29-a02a-679519aec24c.sh: line 1: ./gradlew: Permission denied
##[error]Process completed with exit code 126.
like image 535
Mohsen Mirhoseini Avatar asked Oct 08 '19 08:10

Mohsen Mirhoseini


People also ask

How do I run Gradlew in terminal?

To run a Gradle command, open a command window on the project folder and enter the Gradle command. Gradle commands look like this: On Windows: gradlew <task1> <task2> … ​ e.g. gradlew clean allTests.


3 Answers

I found the answer!

I just had to change the gradlew file permission on the git repository to make it executable using this command:

git update-index --chmod=+x gradlew
git commit -m "Make gradlew executable"

it was simple but killed my time!

like image 98
Mohsen Mirhoseini Avatar answered Oct 23 '22 07:10

Mohsen Mirhoseini


To solve this issue, you might need to add chmod action before gradle one. Like this one:

- name: Change wrapper permissions
  run: chmod +x ./gradlew

So overall workflow file may look like this:

name: Java CI

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v1
    - name: Set up JDK 1.8
      uses: actions/setup-java@v1
      with:
        java-version: 1.8
    - name: Change wrapper permissions
      run: chmod +x ./gradlew
    - name: Build with Gradle
      run: ./gradlew build
like image 20
TSB99X Avatar answered Oct 23 '22 09:10

TSB99X


Just wanted to mention another potential issue that happened to me even though the above changes were made.

I made the mistake of:

./gradle

when it was supposed to be

./gradlew
like image 1
Mark Lapasa Avatar answered Oct 23 '22 07:10

Mark Lapasa