It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do I use Bitbucket Pipelines for a gradle build?

Sigge Birgisson Jul 03, 2016

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

5 answers

1 accepted

3 votes
Answer accepted
Joshua Tjhin Atlassian Team Mar 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
3 votes
Joshua Tjhin Atlassian Team Jul 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 Jul 11, 2016

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

Like Aliaksandr Pashukevich likes this
Joshua Tjhin Atlassian Team Jul 11, 2016

I believe it just needs java so you could use

 

image: java:7
Akos Menyhert Nov 04, 2016

I got bash: ./gradlew: Permission denied

bash: ./gradlew: Permission denied

Error. What should I do?

Akos Menyhert Nov 04, 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 Nov 05, 2016

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

Akos Menyhert Nov 07, 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 Dec 12, 2016

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

Carl Walker Dec 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 Dec 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..
Carl Walker Dec 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 Dec 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
Oleksii Ponomarov Dec 22, 2016

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

Joshua Tjhin Atlassian Team Mar 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
Kashif-Ur-Rehman Jan 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
Kashif-Ur-Rehman Jan 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 

0 votes
Jie Li Nov 06, 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?

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Opsgenie

Handling Opsgenie Alerts

Hi everyone, welcome to the kb articles for Opsgenie FAQs. I'm one of the Technical Support Engineers for Opsgenie who will be providing weekly posts on FAQs from customers.   All alerts are ...

10 views 0 1
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you