Using gradle as build tool

Hi,
I’m using circleci/python:3.7 and I want to add Gradle to this image.
I added the next command:
install_gradle:
description: “Install gradle”
steps:
- run:
command: |
wget -O ~/gradle-5.4.1-bin.zip https://services.gradle.org/distributions/gradle-5.4.1-bin.zip
sudo apt-get install unzip
sudo mkdir /opt/gradle
sudo unzip -d /opt/gradle ~/gradle-5.4.1-bin.zip
sudo touch /etc/profile.d/gradle.sh
sudo echo “export GRADLE_HOME=/opt/gradle/gradle-5.4.1” >> /etc/profile.d/gradle.sh
sudo echo “PATH={GRADLE_HOME}/bin:{PATH}” >> /etc/profile.d/gradle.sh
sudo chmod +x /etc/profile.d/gradle.sh
sudo source /etc/profile.d/gradle.sh
gradle -v

But I have a permission problem to install.
Does anyone have any idea how to install it?

Hi Uri, welcome! There are a number of commands there, can you share the error you are getting so we can help figure out which one is having the permissions problem?

Sure.
The error is: /bin/bash: line 5: /etc/profile.d/gradle.sh: Permission denied

It looks like it’s the sudo touch /etc/profile.d/gradle.sh command then, if I’m counting lines correctly.

Which is strange, since you are using sudo. Can you check if the /etc/profile.d/ directory exists first?

Yes I will check it

The problematic command is:
sudo echo “export GRADLE_HOME=/opt/gradle/gradle-5.4.1” >> /etc/profile.d/gradle.sh

Ah, I’m run into that before. You will want to | sudo tee if I recall, instead of the >> since that doesn’t have permission.

Working !!!
Thanks you !

1 Like