How do I use Bitbucket Pipelines for a gradle build?

sbirgisson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 2016

I am using gradle, what do I need to do?

5 answers

1 accepted

4 votes
Answer accepted
xtjhin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2017

Add the Gradle Wrapper to your repository

Our recommended approach (and Gradle's) to building Gradle projects is to commit the Gradle Wrapper to your repository.

The Gradle wrapper ensures two things:

  • the build environment doesn't need to have Gradle manually installed
  • your project will always be built with the same Gradle version

We recommend making the wrapper script executable before committing it to your repository. In Unix/Mac:

chmod +x gradlew

Then you can build your Gradle project with the wrapper:

image: java:8
pipelines:
  default:
    - step:
        script:
          - bash ./gradlew build
nasibulloh April 9, 2020

It did not work, I got ./gradlew  is not found error. I am using Java 11. Should I configure Gradle for each steps?

4 votes
xtjhin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 10, 2016

If you have a the Gradle Wrapper committed to your repository, it's as easy as:

image: java:8
pipelines:
  default:
    - step:
        script:
          - bash ./gradlew clean build
Igor Ganapolsky July 11, 2016

Does it have to be `java:8`?  Is 7 supported?

Like Deleted user likes this
xtjhin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
July 11, 2016

I believe it just needs java so you could use

 

image: java:7
Akos Menyhert November 4, 2016

I got bash: ./gradlew: Permission denied

bash: ./gradlew: Permission denied

Error. What should I do?

Akos Menyhert November 4, 2016

I try the following: 

pipelines:
  default:
    - step:
        script: # Modify the commands below to build your repository.
          - chmod +x gradlew
          - ./gradlew assembleDebug

Unfortunately it did not works for me. I didnt have permission to change the file access.  

Carey Evans November 5, 2016

Because it's a Bash script, you can just write - bash ./gradlew assembleDebug.

Akos Menyhert November 7, 2016

It works! Thank you!
So the correct bitbucket-pipelines.yml content is:

image: java:7
pipelines:
  default:
    - step:
        script:
          - bash ./gradlew assembleDebug
Kashif-Ur-Rehman December 12, 2016

@Carey Evans, I am following above tutorial, but build is failing .
Logs says that:-
 bash: ./gradlew: No such file or directory 

walkerca December 16, 2016

Hi,

I'm getting a build failure too.

This is from a gradle project

+ bash ./gradlew clean buildError: Could not find or load main class org.gradle.wrapper.GradleWrapperMain

I'm using this configuration

image: java:8
pipelines:
  default:
    - step:
        script:
          - bash ./gradlew clean build
Kashif-Ur-Rehman December 16, 2016

@Carl Walker.
You can try this one:-

image: qlik/gradle
 
pipelines:
  default:
    - step:
        script:
          - gradle test
          - gradle build
          - gradle war

 

 

you have to 

  - cd build
because gradle create war inside that build/libs..
walkerca December 16, 2016

Thanks Kashif.  It looks like "gradle build" with the qlik/gradle image will work.  It's still failing, but on a missing JavaFX jar.  The command is successfully invoked.

Kashif-Ur-Rehman December 16, 2016

@Carl Walker

You can find your war inside 

build/libs folder, means after gradle war command you should run 
- cd build
          - ls
          - cd libs
          - ls
SmsParser December 22, 2016

Hi, is it possible to set storePassword and keyPassword for signingConfigs? 

xtjhin
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 27, 2017

Apologies all. You need to either commit the wrapper as an executable

chmod +x gradlew

or run it through bash:

image: java:8
pipelines:
  default:
    - step:
        script:
          - bash ./gradlew clean build
1 vote
sbirgisson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 3, 2016
Kashif-Ur-Rehman January 23, 2017

@Sigge Birgisson,
I followed your above mentioned url i,e
https://bitbucket.org/hascode/bitbucket-vertx3-pipeline/src/a2befa4ce4b15d970d9c4f7952ebf2578861f6b3/bitbucket-pipelines.yml?at=master&fileviewer=file-view-default


and here is my script:-

# This is a sample build configuration for Gradle.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: qlik/gradle

pipelines:
default:
- step:
script:
- gradle clean
- gradle test
- gradle ear





but previously it was working fine from last 2 months, but today when i start build, it fails on 
gradle clean command  by saying that:-
.sh line 22 gradle command not found bibucket pipeline


Can you help me?
thanks in advance 

 

0 votes
Jie Li November 6, 2018

I have gradle wrapper running in pipeline, but every step it re-downloads the gradle files even I set

 

caches:
- gradle
- gradlewrapper

definitions:
caches:
#location of wrapper in my project
gradlewrapper: ~/gradle/wrapper

 After I check the pipeline log, I see that the pipeline download gradle wrapper to `.gradle/wrapper`, so why is it a different location?

0 votes
Kashif-Ur-Rehman January 26, 2017

@Joshua Tjhin,

I followed follwing

https://bitbucket.org/hascode/bitbucket-vertx3-pipeline/src/a2befa4ce4b15d970d9c4f7952ebf2578861f6b3/bitbucket-pipelines.yml?at=master&fileviewer=file-view-default


and here is my script:-

# This is a sample build configuration for Gradle.
# Check our guides at https://confluence.atlassian.com/x/VYk8Lw for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
image: qlik/gradle

pipelines:
default:
- step:
script:
- gradle clean
- gradle test
- gradle ear





but previously it was working fine from last 2 months, but today when i start build, it fails on 
gradle clean command  by saying that:-
.sh line 22 gradle command not found bibucket pipeline


Can you help me?
thanks in advance 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events