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
22
votes
3 answers

How to get ext.* variables into plugins block in build.gradle.kts

My build file looks like this: val nexusBaseUri: String by extra val gradle_version: String by extra val kotlin_version: String by extra buildscript { val nexusBaseUri by extra { "https://mynexusserver/nexus" } val gradle_version by extra {…
Andy
  • 8,749
  • 5
  • 34
  • 59
22
votes
7 answers

How to resolve Gradle plugin requires Studio 3.0 minimum

I am getting Error:This Gradle plugin requires Studio 3.0 minimum when importing project Project repo: https://github.com/chrisbanes/cheesesquare I had tried mentioned solution provided here and here but nothing worked :(
Vaibhav Singh
  • 1,554
  • 3
  • 13
  • 27
22
votes
1 answer

Android: force gradle to include only one version of a library

I use 'com.android.support:support-v4:23.3.0' in my build.gradle but when explore external libraries I see two version of support-v4 library (23.3.0 & 24.0.0). How can I find which dependency use support-v4:24.0.0 library? How can I force gradle to…
Mneckoee
  • 2,802
  • 6
  • 23
  • 34
22
votes
3 answers

How to properly specify jcenter repository in maven config?

In Gradle, I need simply add: repositories { jcenter() } What is the simplest and proper way to do the same in maven pom.xml or where can I get right url for jcenter repository.
Ihor Rybak
  • 3,091
  • 2
  • 25
  • 32
22
votes
6 answers

compileReleaseKotlin fails with java.lang.ClassNotFoundException: com.sun.tools.javac.util.Context

I'm trying to build my Android Project (which contains a library module) via terminal using gradlew. From within Android Studio, it compiles and installs successfully but, when I try to run ./gradlew assembleDebug I get the following…
Humble Student
  • 3,755
  • 4
  • 20
  • 35
22
votes
2 answers

Gradle Jacoco - Could not find method jacocoTestReport()

I'm trying to generate a Jacoco test report in Gradle. When I try to sync my code, I will receive the following error: Error:(56, 0) Could not find method jacocoTestReport() for arguments [build_38ehqsoyd54r3n1gzrop303so$_run_closure4@10012308] on…
Guido
  • 1,161
  • 3
  • 12
  • 33
22
votes
3 answers

Force CMake in verbose mode via Gradle and the Android NDK

I'm using Gradle and CMake to compile an Android NDK project from the command line. Previously, I was using Ant and ndk-build but I'm trying to migrate the project completely to Gradle and CMake. In my build.gradle I have the following lines to…
Andreas
  • 9,245
  • 9
  • 49
  • 97
22
votes
2 answers

Gradle add nested subproject from a multi-module project as dependency of another subproject

I have a complex, but interesting situation. This is a tree diagram of my folder structure: root |___ settings.gradle |___ p1 |___ p2 // depends on p3/sp1 |___ p3 |____|___sp1 |____|___sp2 I hope that explains the situation. Now how would I add…
smac89
  • 39,374
  • 15
  • 132
  • 179
22
votes
6 answers

How to pass BuildConfig values to dependency module?

I have some configured values in BuildConfig of App module. I want to pass those values to MyLib's BuildConfig which is dependency of App module. Is it possible?
Ramki Anba
  • 754
  • 1
  • 10
  • 21
22
votes
3 answers

What exactly is "task type" in gradle?

I can declare a type for a gradle task and doing so seems to inherit some methods. For example: task myCopyTask(type: Copy){ from "foo" into "bar" } So, I think myCopyTask is an instance of org.gradle.api.tasks.Copy class, yes? And if I declare…
hummingV
  • 1,014
  • 1
  • 11
  • 25
22
votes
3 answers

What is the difference between gradlew build and gradlew assembleRelease

I want to build apk from command line with the help of gradle. Which command should I use to build apks for only release flavours?
Amey Jahagirdar
  • 455
  • 1
  • 4
  • 14
22
votes
1 answer

Gradle - equivalent of test {} configuration block for android

Gradle has the test configuration block https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html ``` apply plugin: 'java' // adds 'test' task test { // enable TestNG support (default is JUnit) useTestNG() // set a system…
sakis kaliakoudas
  • 2,039
  • 4
  • 31
  • 51
22
votes
1 answer

How to understand the output of command 'gradle dependencies'?

There is part of the output: output of gradle dependencies What does the symbols ('+','\','->','()','(*)') exactly mean?
Jerry.L
  • 223
  • 1
  • 3
  • 6
22
votes
3 answers

Configure IntelliJ auto-completion for gradle script in kotlin

I am trying out gradle-script-kotlin with simple hello-world application in IntelliJ. But IntelliJ auto-completion doesn't popup in build.gradle.kts…
TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125
22
votes
2 answers

Gradle dependency for compile time only and test

I am basically looking for a way to mimic the maven dependency provided. I am building a jar (an extension to a db driver), which depends on another jar (the db driver), but I do not want to include that jar. I am able to use compileOnly to achieve…
st-h
  • 2,444
  • 6
  • 37
  • 60