Gradle

  • Build and dependency management
  • default for Android and Kotlin projects
  • It supports two languages: groovy and kotlin
  • dependency:
    • specific library/artifact found in a remote repository such as Maven Central or Google Maven
  • dependency configuration:
    • grouping of dependencies. Common examples include implementation and testImplementation, both made available by the Java plugin.
    • By default Gradle doesn’t come with any dependency configurations.
  • group is same as groupId in maven
  • module is same as artifactId in maven

Files

  • build.gradle
  • service/build.gradle
  • settings.gradle
  • gradle.properties

Gradle Wrapper

  • Gradle Wrapper has scripts that can be run on OS:
    • gradlew.sh*nix OSs
    • gradlew.bat — Windows
  • Can be used to install different versions of gradle and define the gradle version for the project

Important Commands

gradle tasks # lists all tasks
gradle -q dependencies # lists all dependencies
gradle build -x test # ignore running test while building 

Plugins

  • Java Plugin
plugins {
    id 'java'
}
  • Spring boot plugin
plugins {
	id 'org.springframework.boot' version '3.2.3'
}
  • Android plugin
plugins {
    id 'com.android.application' version '8.2.2' apply false
    id 'com.android.library' version '8.2.2' apply false
    id 'org.jetbrains.kotlin.android' version '1.9.20' apply false
}

Java plugin

  • It is one of the core plugin: https://docs.gradle.org/current/userguide/plugin_reference.html#plugin_reference
  • Supported Tasks:
    • compileJava
    • compileTestJava: depends on classes
    • classes
    • testClasses
    • test: depends on testClasses
    • clean
  • Dependency between tasks:
    java plugin
  • Source sets:
    • main
    • test
  • Dependency Configurations:
    • implementation
    • compileOnly
    • runtimeOnly etc.
  • Dependency configs relationship
    • green: dep. config: we can declare own dependencies
    • grey: dep. config: can’t declare own dependencies. used only by task
    • cyan: task
  • main sourceset:
    java_plugin_main_sourceset
  • test sourceset:
    java_plugin_test_sourceset

3 items under this folder.