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
23
votes
9 answers

How to access files from assets folder during tests execution?

How to access files from assets folder during unit tests execution? My project is build using Gradle, I use Robolectric to run tests. It seems like gradle is being recognizing the assets: This is how I'm struggling to read the file: public String…
Eugene
  • 59,186
  • 91
  • 226
  • 333
23
votes
4 answers

Is resource filtering in Gradle possible without using tokens?

The recommended way to do resource filtering in Gradle is by having tokens in the properties file and then replacing them when processing. Example # config.properties hostname = @myhost@ and in build.gradle do something like below processResources…
Krishnaraj
  • 2,360
  • 1
  • 32
  • 55
23
votes
4 answers

Wear App and with custom build type with applicationIdSuffix

I have an app where I'd like to add an Android Wear app extension. The main app has three build types (debug, beta and release). Beta builds have an applicationIdSuffix which allows me to install the play-store version and the current development…
Tom
  • 5,068
  • 5
  • 29
  • 41
23
votes
7 answers

Android Studio gradle doesn't compile the specified version

I've been developing this small project for some days now but suddenly today, Android Studio started to give me this error Error:Execution failed for task ':app:processDebugManifest'. > Manifest merger failed : uses-sdk:minSdkVersion 14 cannot be…
23
votes
3 answers

Android Gradle Running Tests on Non-Debug Builds

I have a project with three different build types: debug, beta, and release. My test package is always created for debug builds, but QA uses the beta build and we want QA to run these tests on their vast array of devices. I'm trying to create a…
Maxwell
  • 6,532
  • 4
  • 37
  • 55
23
votes
4 answers

Using Gradle to split external libraries in separated dex files to solve Android Dalvik 64k methods limit

Is there a proper/easy way to solve the 64k methods limit using Gradle? I mean some custom Gradle task to use pre-dexed jars to create separated dex files, instead of a single classes.dex. Thank you Ivan Current status Currently, I'm struggling with…
Ivan Morgillo
  • 2,837
  • 4
  • 30
  • 46
23
votes
2 answers

Test package for different flavors in Android Studio

I am experimenting flavors on an application in androidstudio. I have to write different test classes for the flavors, as I have different class files for the flavors. But I wonder if there is any option to specify test packages for each flavor in…
23
votes
7 answers

Force Android Studio to download and install gradle 1.10 or 1.1

I installed Android Studio 0.5.1 and my project is not working any more. Error it provides is: The project is using an unsupported version of Gradle. Please use version 1.10. I tried to change settings in gradle-wrapper.properties and…
Draško
  • 2,119
  • 4
  • 41
  • 73
23
votes
4 answers

How to set system property using gradle?

I was wondering if it's possible to set a system property, for a Java application, using Gradle? I tried using gradle.properties file and defining a property as systemProp.name = my name but then when I try to get that property from a Java…
markovuksanovic
  • 15,676
  • 13
  • 46
  • 57
23
votes
5 answers

Debug Signing Config on Gradle Product Flavors

I've got a project where I have several device-specific product flavors, and each flavor needs to be signed with a different config: productFlavors { nexus7 { signingConfig signingConfigs.nexus7 } nexus4 { signingConfig…
MJMWahoo06
  • 258
  • 2
  • 8
23
votes
3 answers

Gradle: What Is The Default Configuration and How Do I Change It

When I run the "dependencies" task there are several sections: compile, runtime, testCompile ... One of those sections is "default - Configuration for default artifacts." What is this section and what is it used for? How do I change what is in the…
Rylander
  • 19,449
  • 25
  • 93
  • 144
23
votes
4 answers

How do I conditionally include or exclude a file from an archetype when project is generated?

I'm creating Maven 2 archetypes for our project (Weld). I would like to be able to control which files are placed into the generated project based on the value of a property that is defined during archetype:generate. For instance, I foresee the…
Dan Allen
  • 2,418
  • 1
  • 16
  • 13
23
votes
6 answers

Gradle + Robolectric: Where do I put the file org.robolectric.Config.properties?

I'm trying to setup a test using Robolectric to click on a menu button in this repository. Basic Robolectric tests will run, but I'm not able to run any project-specific test using resources because it says it can't find my AndroidManifest.xml. …
Rob Hawkins
  • 451
  • 1
  • 5
  • 17
23
votes
2 answers

Make one source set dependent on another

I have an integration test source set in gradle, and it is dependent on my main classes being compiled. I set that up by doing integrationTestClasses.dependsOn 'classes' Is this the way to do it, or is there a way to setup dependencies on source…
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406
23
votes
3 answers

run single integration test with gradle

I'm trying to run a single integration tests using gradle's -Dtest.single flag. I have added another source set, src/integrationTest and put the tests in there. I have an integration test task task integrationTests(type: Test) { dependsOn…
Jeff Storey
  • 56,312
  • 72
  • 233
  • 406