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
223
votes
28 answers

Android Studio suddenly cannot resolve symbols

Android Studio 0.4.2 was working fine and today I opened it and almost everything was red and the auto-completion had stopped working. I look at the imports and AS seems to be telling me it can't find android.support.v4 all of a sudden (offering me…
Daniel Wilson
  • 18,838
  • 12
  • 85
  • 135
221
votes
4 answers

Gradle alternate to mvn install

I have 2 different project build on mvn. I am trying to replace to Gradle. Project 1 is an SDK, and project 2 is using that sdk (example). In the time of maven it creates artifact using mvn install which adds the whole project into local…
Rajmahendra
  • 3,092
  • 3
  • 31
  • 42
220
votes
2 answers

What is the syntax for writing comments in build.gradle file?

Looking down this build.gradle file apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "package.myapp" minSdkVersion 19 …
Machado
  • 14,105
  • 13
  • 56
  • 97
219
votes
8 answers

Where to put Gradle configuration (i.e. credentials) that should not be committed?

I'm trying to deploy a Gradle-built artifact to a Maven repo, and I need to specify credentials for that. This works fine for now: uploadArchives { repositories { mavenDeployer { repository(url:…
Lóránt Pintér
  • 10,152
  • 14
  • 47
  • 53
217
votes
6 answers

Why should the Gradle Wrapper be committed to VCS?

From Gradle's documentation: The scripts generated by this task are intended to be committed to your version control system. This task also generates a small gradle-wrapper.jar bootstrap JAR file and properties file which should also be committed…
farmer1992
  • 7,816
  • 3
  • 30
  • 26
216
votes
26 answers

Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat

If I run gradle assembleDebug from the command line, I am suddenly getting this error: UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dx.util.DexException: Multiple dex files define…
xrd
  • 4,019
  • 6
  • 30
  • 39
215
votes
17 answers

Gradle proxy configuration

I need web access from Gradle through a proxy server to use the Gradle/Artifactory integration for Jenkins. To reduce possible causes for issues, I manually add the Artifactory plugin in build.gradle and run it from command line: apply { apply…
Daniel Beck
  • 6,363
  • 3
  • 35
  • 42
215
votes
53 answers

Flutter App stuck at "Running Gradle task 'assembleDebug'... "

When I run the app it get stuck Launching lib\main.dart on Lenovo A319 in debug mode... Running Gradle task 'assembleDebug'... (This is taking an unexpectedly long time.) It never initialize Gradle nor the dependencies
learner
  • 2,191
  • 2
  • 6
  • 10
215
votes
11 answers

Is there a way to list task dependencies in Gradle?

./gradle tasks lists "some" of the tasks. Looking at http://gradle.org/docs/current/userguide/java_plugin.html there are hidden ones not listed. Also, other plugins will not have such a nice pretty graph of the dependencies between tasks. Is…
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
208
votes
17 answers

Multi-project test dependencies with gradle

I have a multi-project configuration and I want to use gradle. My projects are like this: Project A -> src/main/java -> src/test/java Project B -> src/main/java (depends on src/main/java on Project A) -> src/test/java (depends on…
mathd
  • 2,415
  • 2
  • 17
  • 8
207
votes
7 answers

Jersey stopped working with InjectionManagerFactory not found

I am receiving below error while running my Jersey API in Tomcat 8.5.11 which is causing my API to stop: HTTP Status 500 - Servlet.init() for servlet Jersey REST Service threw exception type Exception report message Servlet.init() for servlet…
gregor
  • 2,397
  • 2
  • 12
  • 18
207
votes
5 answers

Gradle build only one module

I have a multiple module gradle build. I want to execute targets for one module using root. Ex : gradle build -Pmodule=ABC gradle jar -Pmodule=ABC gradle test -Pmodule=ABC gradle compileJava -Pmodule=ABC gradle customTask -Pmodule=ABC etc. So…
Viraj
  • 5,083
  • 6
  • 35
  • 76
205
votes
14 answers

Gradle - Could not target platform: 'Java SE 8' using tool chain: 'JDK 7 (1.7)'

I am trying to import Gradle project in Intellij Idea with local Gradle distrib and getting stacktrace with the following message: Could not target platform: 'Java SE 8' using tool chain: 'JDK 7 (1.7)'. Could anyone explain please what could be the…
Vasiliy Vlasov
  • 3,316
  • 3
  • 17
  • 20
205
votes
6 answers

What does transitive = true in Gradle exactly do (w.r.t. crashlytics)?

What does Gradle transitive = true do exactly? It is not clear from the Gradle documentation. This is in the context of compile within build.gradle. In my case I'm depending Android's…
Steve Kuo
  • 61,876
  • 75
  • 195
  • 257
200
votes
40 answers

Android- Error:Execution failed for task ':app:transformClassesWithDexForRelease'

The Problem is that i am able to run my app when i change to debug mode but it fails when i switch to release mode. Exception: **FAILURE: Build failed with an exception.** > Execution failed for task ':app:transformClassesWithDexForRelease'. >…