How do I use Bitbucket Pipelines for a gradle build?

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

4 answers

1 accepted

This widget could not be displayed.
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
This widget could not be displayed.
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 

 

This widget could not be displayed.

@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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in Teamwork

What teamwork quotes inspire you?

Hey everyone! My name is Natalie and I'm an editor of the Atlassian Blog and I've got a question for you: What's your favorite quote about teamwork?  We've compiled a list here, along with...

176 views 18 7
Join discussion

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