Azure Pipeline for Gradle without wrapper

Viewed 548

I am creating a pipeline for a project where Gradle is used. They are not using wrapper script. When I add the task Gradle@2, I dont see an option to run the gradle commands. it has only gradlew . even if I give gradle, it doesnt work

- task: Gradle@2
  inputs:
    workingDirectory: 'AzureFunctions'
    tasks: 'jar --info'
    jdkVersionOption: '11.0.9.1'

Please correct me if I am using the right task for Gradle commands

2 Answers

@Francisco is correct, Gradle task is used to build using a Gradle wrapper script. You don’t need to install Gradle if the build has a Gradle Wrapper, and use of the Gradle Wrapper is the recommended way to upgrade Gradle.

You could generate a wrapper from your Gradle project. The Gradle wrapper allows the build agent to download and configure the exact Gradle environment that is checked into the repository without having any software configuration on the build agent itself other than the JVM.

  1. Create the Gradle wrapper by issuing the following command from the root project directory where your build.gradle resides:

    jamal@fabrikam> gradle wrapper

  2. Upload your Gradle wrapper to your remote repository.

    There is a binary artifact that is generated by the gradle wrapper ( located at gradle/wrapper/gradle-wrapper.jar ). This binary file is small and doesn't require updating. If you need to change the Gradle configuration run on the build agent, you update the gradle-wrapper.properties.

The repository should look something like this:

|-- gradle/
    `-- wrapper/
        `-- gradle-wrapper.jar
        `-- gradle-wrapper.properties
|-- src/
|-- .gitignore
|-- build.gradle
|-- gradlew
|-- gradlew.bat

Check this link for more details:

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/gradle?view=azure-devops#how-do-i-generate-a-wrapper-from-my-gradle-project

If you insist on using gradle alone, you would need to configure a self-hosted agent and install gradle by following the documentation below. Then use Command Line task to run gradle.

https://docs.gradle.org/current/userguide/installation.html

Related