How do I use Bitbucket Pipelines for a gradle build?

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

4 answers

1 accepted

1 vote
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
2 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

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

Joshua Tjhin Atlassian Team Jul 11, 2016

I believe it just needs java so you could use

 

image: java:7

I got bash: ./gradlew: Permission denied

bash: ./gradlew: Permission denied

Error. What should I do?

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.  

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

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

image: java:7
pipelines:
  default:
    - step:
        script:
          - bash ./gradlew assembleDebug

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

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

@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..

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.

@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

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

@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 

 

@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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Marketplace Apps

Tips on how to choose the best estimation method for your planning

Planning and grooming sessions all come with their own sets of rules. Team members meet to estimate stories or other work items, all according to an agreed-upon process. And with every session comes ...

71 views 0 11
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you