Search code examples
gradlegithubcontinuous-integrationgithub-actions

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.

Solution

  • 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!


    Update: The solution above is fixing the file permission, another solution is adding the permission fix step to the flow before execution,

    name: Java CI
    
    on: [push]
    
    jobs:
      build:
    
        runs-on: ubuntu-latest
    
        steps:
        - uses: actions/checkout@v2
        - name: Set up JDK
          uses: actions/setup-java@v1
          with:
            java-version: 11
    
        - name: Change wrapper permissions
          run: chmod +x ./gradlew
        - name: Build with Gradle
          run: ./gradlew build