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
1438
votes
27 answers

What is Gradle in Android Studio?

Gradle is a bit confusing to me, and also for any new Android developer. Can anyone explain what Gradle in Android Studio is and what its purpose is? Why is it included in Android Studio?
1280
votes
12 answers

What's the difference between implementation, api and compile in Gradle?

After updating to Android Studio 3.0 and creating a new project, I noticed that in build.gradle there is a new way to add new dependencies instead of compile there is implementation and instead of testCompile there is testImplementation. Example: …
1074
votes
35 answers

Android Studio: Add jar as library?

I'm trying to use the new Android Studio but I can't seem to get it working correctly. I'm using the Gson library to serialize/deserialize JSON-objects. But the library somehow isn't included in the build. I had created a new project with just a…
985
votes
26 answers

How can I force Gradle to redownload dependencies?

How can I tell Gradle to redownload dependencies from repositories?
fedor.belov
  • 22,343
  • 26
  • 89
  • 134
867
votes
44 answers

Android Studio Error "Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8"

I downloaded the newest Android Studio, and I wanted to run the Android Jetpack Compose Project, but when I ran it, I got the error: > Failed to apply plugin 'com.android.internal.application'. > Android Gradle plugin requires Java 11 to run. You…
Ven Shine
  • 8,739
  • 2
  • 9
  • 24
821
votes
11 answers

Gradle build without tests

I want to execute gradle build without executing the unit tests. I tried: $ gradle -Dskip.tests build That doesn't seem to do anything. Is there some other command I could use?
Dave
  • 13,518
  • 7
  • 42
  • 51
808
votes
21 answers

How to add local .jar file dependency to build.gradle file?

I have tried to add my local .jar file dependency to my build.gradle file: apply plugin: 'java' sourceSets { main { java { srcDir 'src/model' } } } dependencies { runtime files('libs/mnist-tools.jar',…
letter Q
  • 14,735
  • 33
  • 79
  • 118
807
votes
24 answers

Error retrieving parent for item: No resource found that matches the given name after upgrading to AppCompat v23

I've always programmed Android with Eclipse and decided to start migrating to Android Studio. I decided to use the same SDK I already had for Eclipse, then: Started a new project Set minimum SDK 4.0 (API Level 14) Choose Blank Activity option Used…
Vini.g.fer
  • 11,639
  • 16
  • 61
  • 90
788
votes
16 answers

Using Gradle to find dependency tree

Is it possible to use Gradle to produce a tree of what depends on what? I have a project and would like to find out all the dependencies so I may be able to prune it a little with forward declarations etc.
user3286701
  • 7,963
  • 3
  • 12
  • 4
638
votes
12 answers

How to run only one unit test class using Gradle?

I am new to Gradle. I use Gradle 1.10 and Ubuntu 13. I want to know if there's any command to execute only one unit test class, similar to testOnly in SBT.
bula
  • 8,719
  • 5
  • 27
  • 44
630
votes
16 answers

How to clear gradle cache?

I'm trying to use Android Studio, and the first time I boot it up, it takes like 45 MINUTES to compile... If I don't quit the application, it is okay - each subsequent compilation/running the app will take around 45 seconds. I've tried to check some…
David T.
  • 22,301
  • 23
  • 71
  • 123
629
votes
35 answers

No matching client found for package name (Google Analytics) - multiple productFlavors & buildTypes

Context: I'm trying to set up Google Analytics for my app. (having 4 custom buildTypes and more than a few productFlavors) It works fine when I select the Build Variant which has the applicationId set to com.my.app.package.name (the package name…
626
votes
20 answers

Can the Android layout folder contain subfolders?

Right now, I'm storing every XML layout file inside the 'res/layout' folder, so it is feasible and simple to manage small projects, but when there is a case of large and heavy projects, then there should be a hierarchy and sub-folders needed inside…
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
616
votes
15 answers

You have not accepted the license agreements of the following SDK components

I downloaded the latest Android SDK tools version 24.4.1. I used the command line to install SDKs. I typed y when asked Do you accept the license 'android-sdk-license-c81a61d9' [y/n]: y after that install succeeded. But when using Gradle 3.1 to…
codable
  • 6,439
  • 3
  • 15
  • 9
607
votes
32 answers

How to create a release signed apk file using Gradle?

I would like to have my Gradle build to create a release signed apk file using Gradle. I'm not sure if the code is correct or if I'm missing a parameter when doing gradle build? This is some of the code in my build.gradle/build.gradle.kts…
Jan-Terje Sørensen
  • 14,468
  • 8
  • 37
  • 37
1
2 3
99 100