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
1 answer

Gradle: Make build version available to Java

By default, all gradle java projects have a version property. Typically, this looks something like: allprojects { apply plugin: 'java' // ... // configure the group and version for this project group = 'org.example' version =…
Martin Häusler
  • 6,544
  • 8
  • 39
  • 66
22
votes
4 answers

Creating a Java Gradle project and building the .jar file in IntelliJ IDEA - How to?

Is there a tutorial explaining how to properly create a Java Gradle project and build the .jar file? When I create a Java project and add Gradle: File -> New -> Module -> Gradle -> ... I receive errors about Java EE websocket's not available (I'm…
Defozo
  • 2,946
  • 6
  • 32
  • 51
22
votes
3 answers

gradle: how do I list tasks introduced by a certain plugin

Probably a simple question but I can't find a way to list which tasks are introduced by the plugins that get applied in a build.gradle file. So, say that your build.gradle is simply: apply plugin: 'java' is there a simple way to make gradle list…
user3837712
22
votes
3 answers

java.util.scanner throws NoSuchElementException when application is started with gradle run

I have a created a simple java "echo" application that takes a user's input and shows it back to them to demonstrate the issue. I can run this application without trouble using IntelliJ's internal "run" command, and also when executing the compiled…
nickbdyer
  • 624
  • 6
  • 13
22
votes
1 answer

How to see the HTML reports Gradle generates in Jenkins

I have a Jenkins CI server running on a Linux VM. Jenkins runs Gradle task (build) and tests for my project. I know the HTML reports for test results are generated in project/build/reports folders. Is there way to see these reports using Jenkins? …
user2047824
  • 633
  • 1
  • 5
  • 16
22
votes
4 answers

Build variants (product flavours) in IntelliJ Java application

Is it possible to have build variants based on different source sets for a traditional Java app (NOT an Android project) in IntelliJ? I'd like to use a feature like productFlavors that comes with the Android gradle plugin, but for a traditional Java…
user3904083
  • 331
  • 2
  • 5
22
votes
1 answer

Kotlin - Intermittent "bad class file" error

Starting today, when I attempt to build my Kotlin Android app, I am met with the following error in my Gradle build: Error:cannot access Baz bad class file:…
John D.
  • 2,521
  • 3
  • 24
  • 45
22
votes
8 answers

Remove Google Play Services from app in Android Studio

I am working on an example app in Android Studio and I somehow accidentally added Google Play Services to one of my Activities. I'm not even sure how I did it, but it added several auto generated methods, variables and imports. I removed all of…
rvb
  • 420
  • 1
  • 8
  • 15
22
votes
5 answers

GAE deploy pagespeed warning

form this morning (January 12 2016) there is a warning message appearing when we deploy to Google App Engine. We don't use PageSpeed so it's surprising that it tries to post something to its URL. 95% Closing update: new version is ready to start…
michal sankot
  • 291
  • 1
  • 9
22
votes
2 answers

Add a dependency to an Android Cordova plugin

I'm building a Cordova Android plugin. I want to use a 3rd party View inside an Intent that is created by the plugin (specifically scissors). Normally (in non Cordova projects) I would go to my project's build.gradle file and add it like…
YakirNa
  • 519
  • 1
  • 5
  • 15
22
votes
2 answers

Shadow Plugin Gradle: What does mergeServiceFiles() do?

In my build.gradle file I need to add the line: shadowJar { mergeServiceFiles() } Otherwise the jar does not run properly. I wonder what this line does exactly? I use the Gradle plugin in Eclipse Luna. I create the jar on one Java project which…
Romain
  • 1,385
  • 2
  • 15
  • 30
22
votes
5 answers

How to exclude a cpp file in experimental gradle?

I'm trying to use Android Studio 1.3.1 to compile an NDK project using the experimental gradle syntax. My build.gradle looks very much like the one from the Teapot example With the exception that my source tree has some files which I don't want to…
shoosh
  • 76,898
  • 55
  • 205
  • 325
22
votes
3 answers

Android Studio -- clear application data for Instrumentation Test

How can I get Android Studio (AndroidJunitRunner) to clear application data preceding an instrumentation test without manually running adb command? I discovered that android.support.test.runner.AndroidJUnitRunner kind of cheats -- it never actually…
22
votes
6 answers

Missing top-level build.gradle in multi-module project

I'm missing the "Top-Level" project build.gradle script from my project: I imported it into Android Studio from a very complex Maven/Eclipse project, and it basically made a module ("android") in the top level of the directory, and added all the…
phreakhead
  • 14,721
  • 5
  • 39
  • 40
22
votes
12 answers

Gradle couldn't find com.android.databinding:dataBinder:1.0-rc0

This is an old question which is irrelevant today. See Android developer's instruction. Applying Databinding to your projects is a lot easier now than four years ago. As I am going over Android Data binding Guide from…
Juan Mendez
  • 2,658
  • 1
  • 27
  • 23
1 2 3
99
100