Questions tagged [gradle]

Gradle is a project build automation tool that uses a Groovy DSL. Gradle build scripts support Maven and Ivy repositories as well as plain file system for dependency management.

Gradle is a build automation tool focused on flexibility and performance. Gradle build scripts are written using a or DSL. Gradle allows the use of , , or user-defined repositories for dependency management.

Why Gradle?

  • Polyglot Builds: build in 60 different programming languages
  • Tool Integration: like , , , etc.
  • Robust Dependency Management
  • Powerful Yet Concise Logic: declarative and imperative
  • High Performance Builds
  • Build Reporting

Gradle allows you to describe the automation of a project build both declaratively and imperatively as you have the full power of the programming language to describe Gradle tasks.

There are many plugins for Gradle. Both native ones like the "War" plugin and third-party ones. These can be found at plugins.gradle.org

Latest Version: 7.6 (Nov 25, 2022)

The default name for the build script is build.gradle

Expressing a project dependency

repositories {
    mavenCentral()
}

dependencies {
    testCompile 'junit:junit:4.12'
}

Defining a task

Using a closure in defining a task count action:

task count {
    doFirst {
        4.times { print "$it " }
    }
}

Output of running gradle -q count:

> gradle -q count
0 1 2 3

Links:

Related tags:

Tips:

51043 questions
603
votes
64 answers

Automatically accept all SDK licences

Since gradle android plugins 2.2-alpha4: Gradle will attempt to download missing SDK packages that a project depends on Which is amazingly cool and was know to be a JakeWharton project. But, to download the SDK library you need to: accept the…
nsvir
  • 8,781
  • 10
  • 32
  • 47
601
votes
35 answers

More than one file was found with OS independent path 'META-INF/LICENSE'

When I build my app, I get the following error: Error: Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. More than one file was found with OS independent path 'META-INF/LICENSE' This is my build.gradle file: apply…
Cyrus
  • 8,995
  • 9
  • 31
  • 58
522
votes
26 answers

How to manually include external aar package using Gradle for Android

I've been experimenting with the new android build system and I've run into a small issue. I've compiled my own aar package of ActionBarSherlock which I've called 'actionbarsherlock.aar'. What I'm trying to do is actually use this aar to build my…
Miguel
  • 19,793
  • 8
  • 56
  • 46
520
votes
23 answers

How do I tell Gradle to use specific JDK version?

I can't figure out to get this working. Scenario: I have an application built with gradle The application uses JavaFX What I want Use a variable (defined per developer machine) which points to an installation of a JDK which will be used for…
bully
  • 5,525
  • 3
  • 22
  • 26
505
votes
6 answers

Gradle DSL method not found: 'runProguard'

I get an error after updating from my last project. Not a problem in my code but I'm having trouble with build.gradle. How can I fix it? build.gradle code here: apply plugin: 'android' android { compileSdkVersion 21 buildToolsVersion…
abaci
  • 5,226
  • 2
  • 12
  • 13
481
votes
19 answers

gradlew: Permission Denied

I am attempting to run gradlew from my command line, but am constantly facing the following error. Brendas-MacBook-Pro:appx_android brendalogy$ ./gradlew compileDebug --stacktrace -bash: ./gradlew: Permission denied I am already running this…
Brenda Nicole Tan
  • 5,164
  • 2
  • 17
  • 17
475
votes
28 answers

Building and running app via Gradle and Android Studio is slower than via Eclipse

I have a multi-project (~10 modules) of which building takes about 20-30 seconds each time. When I press Run in Android Studio, I have to wait every time to rebuild the app, which is extremely slow. Is it possible to automate building process in…
froger_mcs
  • 13,972
  • 5
  • 23
  • 34
471
votes
8 answers

Gradle Implementation vs API configuration

I'm trying to figure out what is the difference between api and implementation configuration while building my dependencies. In the documentation, it says that implementation has better build time, but, seeing this comment in a similar question I…
reinaldomoreira
  • 5,388
  • 3
  • 14
  • 29
462
votes
11 answers

Is it possible to declare a variable in Gradle usable in Java?

Is it possible to declare a variable in Gradle usable in Java ? Basically I would like to declare some vars in the build.gradle and then getting it (obviously) at build time. Just like a pre-processor macros in C/C++... An example of declaration…
klefevre
  • 8,595
  • 7
  • 42
  • 71
434
votes
18 answers

How to update gradle in android studio?

I installed Android Studio 0.1.9. Today I got and update to version 0.2 and of course I updated. After the installation I restarted Android Studio but now I get this message: Project is using an old version of the Android Gradle plug-in. The …
7heViking
  • 7,137
  • 11
  • 50
  • 94
404
votes
16 answers

How to define Gradle's home in IDEA?

I am trying to import a Gradle project into IntelliJ, and when I get to the Gradle Home textbox, it is not automatically populated, nor will typing in the path of Gradle Home result in a valid location - I have the GRADLE_USER_HOME environment…
user2699970
  • 4,043
  • 2
  • 13
  • 5
392
votes
7 answers

What the difference in applying gradle plugin

I don't understand gradle plugins block apply plugin: 'someplugin1' apply plugin: 'maven' and other one: plugins { id 'org.hidetake.ssh' version '1.1.2' } In first block We have some plugin name. in second one package and version. I don't…
Yevgen Kulik
  • 5,713
  • 2
  • 22
  • 44
385
votes
14 answers

appcompat-v7:21.0.0': No resource found that matches the given name: attr 'android:actionModeShareDrawable'

When attempting to use the latest appcompat-v7 support library in my project, I get the following…
383
votes
25 answers

HttpClient won't import in Android Studio

I have a simple class written in Android Studio: package com.mysite.myapp; import org.apache.http.client.HttpClient; public class Whatever { public void headBangingAgainstTheWallExample () { HttpClient client = new…
AndroidDev
  • 20,466
  • 42
  • 148
  • 239
364
votes
12 answers

java.lang.NoClassDefFoundError:failed resolution of :Lorg/apache/http/ProtocolVersion

I'm encountering this error when I use Android Studio to build my app. The APK is compiled, but when I attempt to run the app on Android P emulator, it will crash and throw the following error. Please see more details in the…