🔏
Tech
  • 🟢App aspects
    • Software architecture
      • Caching
      • Anti-patterns
      • System X-ability
      • Coupling
      • Event driven architecture
        • Command Query Responsibility Segregation (CQRS)
        • Change Data Capture (CDC)
      • Distributed transactions
      • App dev notes
        • Architecture MVP
      • TEMP. Check list
      • Hexagonal arch
      • Communication
        • REST vs messaging
        • gRPC
        • WebSocket
      • Load balancers
      • Storage limits
      • Event storming
    • Authentication
    • Deployment strategy
  • Databases
    • Classification
    • DB migration tools
    • PostreSQL
    • Decision guidance
    • Index
      • Hash indexes
      • SSTable, LSM-Trees
      • B-Tree
      • Engines, internals
    • Performance
  • System design
    • Interview preparation
      • Plan
        • Instagram
        • Tinder
        • Digital wallet
        • Dropbox
        • Live video streaming
        • Uber
        • Whatsup
        • Tiktok
        • Twitter
        • Proximity service
    • Algorithms
    • Acronyms
  • 🟢Programming languages
    • Java
      • Features
        • Field hiding
        • HashCode() and Equals()
        • Reference types
        • Pass by value
        • Atomic variables
      • Types
      • IO / NIO
        • Java NIO
          • Buffer
          • Channel
        • Java IO: Streams
          • Input streams
            • BufferedInputStream
            • DataInputStream
            • ObjectInputStream
            • FilterInputStream
            • ByteArrayInputStream
        • Java IO: Pipes
        • Java IO: Byte & Char Arrays
        • Java IO: Input Parsing
          • PushbackReader
          • StreamTokenizer
          • LineNumberReader
          • PushbackInputStream
        • System.in, System.out, System.error
        • Java IO: Files
          • FileReader
          • FileWriter
          • FileOutputStream
          • FileInputStream
      • Multithreading
        • Thread liveness
        • False sharing
        • Actor model
        • Singleton
        • Future, CompletableFuture
        • Semaphore
      • Coursera: parallel programming
      • Coursera: concurrent programming
      • Serialization
      • JVM internals
      • Features track
        • Java 8
      • Distributed programming
      • Network
      • Patterns
        • Command
      • Garbage Collectors
        • GC Types
        • How GC works
        • Tools for GC
    • Kotlin
      • Scope functions
      • Inline value classes
      • Coroutines
      • Effective Kotlin
    • Javascript
      • Javascript vs Java
      • TypeScript
    • SQL
      • select for update
    • Python
  • OS components
    • Network
      • TCP/IP model
        • IP address in action
      • OSI model
  • 🟢Specifications
    • JAX-RS
    • REST
      • Multi part
  • 🟢Protocols
    • HTTP
    • OAuth 2.0
    • LDAP
    • SAML
  • 🟢Testing
    • Selenium anatomy
    • Testcafe
  • 🟢Tools
    • JDBC
      • Connection pool
    • Gradle
    • vim
    • git
    • IntelliJ Idea
    • Elastic search
    • Docker
    • Terraform
    • CDK
    • Argo CD
      • app-of-app setup
    • OpenTelemetry
    • Prometheus
    • Kafka
      • Consumer lag
  • 🟢CI
    • CircleCi
  • 🟢Platforms
    • AWS
      • VPC
      • EC2
      • RDS
      • S3
      • IAM
      • CloudWatch
      • CloudTrail
      • ELB
      • SNS
      • Route 53
      • CloudFront
      • Athena
      • EKS
    • Kubernetes
      • Networking
      • RBAC
      • Architecture
      • Pod
        • Resources
      • How to try
      • Kubectl
      • Service
      • Tooling
        • ArgoCD
        • Helm
        • Istio
    • GraalVM
    • Node.js
    • Camunda
      • Service tasks
      • Transactions
      • Performance
      • How it executes
  • 🟢Frameworks
    • Hibernate
      • JPA vs Spring Data
    • Micronaut
    • Spring
      • Security
      • JDBC, JPA, Hibernate
      • Transactions
      • Servlet containers, clients
  • 🟢Awesome
    • Нейробиология
    • Backend
      • System design
    • DevOps
    • Data
    • AI
    • Frontend
    • Mobile
    • Testing
    • Mac
    • Books & courses
      • Path: Java Concurrency
    • Algorithms
      • Competitive programming
    • Processes
    • Finance
    • Electronics
  • 🟢Electronics
    • Arduino
    • IoT
  • Artificial intelligence
    • Artificial Intelligence (AI)
  • 🚀Performance
    • BE
  • 📘Computer science
    • Data structures
      • Array
      • String
      • LinkedList
      • Tree
    • Algorithms
      • HowTo algorithms for interview
  • 🕸️Web dev (Frontend)
    • Trends
    • Web (to change)
  • 📈Data science
    • Time series
Powered by GitBook
On this page
  • Configuration
  • Source sets
  • Dependencies
  • Dependency configurations
  • Resolvable and consumable configurations
  • Api vs Implementation
  • Java plugin
  • Project layout
  • Configurations
  • Java extension
  • Dependency hell
  • Modules
  • subprojects vs allprojects
  • Build lifecycle
  • Version catalog

Was this helpful?

  1. Tools

Gradle

https://docs.gradle.org/current/userguide/userguide_single.html

PreviousConnection poolNextvim

Last updated 9 months ago

Was this helpful?

Configuration

Configuration is a named set of dependencies grouped together as a specific goal.

Source sets

  • the source files and where they’re located

  • the compilation classpath, including any required dependencies (via Gradle )

  • where the compiled class files are placed

sourceSet is a placeholder (for main source set it is default)

Dependencies

  • Repository => e.g. mavenCentral()

  • Configuration => e.g. implementation

  • Module coordinate => '<groupId>:<artifactId>:<version>'

Dependency configurations

Every dependency declared for a Gradle project applies to a specific scope. Many Gradle plugins add pre-defined configurations to your project.

Configuration inheritance and composition

Child configurations inherit the whole set of dependencies declared for any of its superconfigurations.

Example

Let’s say you wanted to write a suite of smoke tests. Each smoke test makes a HTTP call to verify a web service endpoint. As the underlying test framework the project already uses JUnit. You can define a new configuration named smokeTest that extends from the testImplementation configuration to reuse the existing test framework dependency.

configurations {
    smokeTest.extendsFrom testImplementation
}

dependencies {
    testImplementation 'junit:junit:4.12'
    smokeTest 'org.apache.httpcomponents:httpclient:4.5.5'
}

Configurations have at least 3 different roles:

  1. to declare dependencies

  2. as a consumer, to resolve a set of dependencies to files

configurations {
    // declare a "configuration" named "someConfiguration"
    // it doesn’t tell us how the configuration is meant to be used
    someConfiguration
}
dependencies {
    // add a project dependency to the "someConfiguration" configuration
    someConfiguration project(":lib")
}
configurations {
    // declare a configuration that is going to resolve the compile classpath of the application
    compileClasspath.extendsFrom(someConfiguration)

    // declare a configuration that is going to resolve the runtime classpath of the application
    runtimeClasspath.extendsFrom(someConfiguration)
}

Api vs Implementation

  • api - both a compile and runtime dependency on this artifact

  • implementation - only a runtime dependency on this artifact

Java plugin

Project layout

  • src/main/java

  • src/main/resources

  • src/test/java

  • src/test/resources

  • src/sourceSet/java

  • src/sourceSet/resources

Configurations

  • Gray text — the configuration is deprecated.

  • Green background — you can declare dependencies against the configuration.

  • Blue-gray background — the configuration is for consumption by tasks, not for you to declare dependencies.

  • Light blue background with monospace text — a task.

Java extension

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

Dependency hell

// investigate test class path
gradle -q dependencyInsight --dependency com.h2database --configuration testRuntimeClasspath

gradle -q dependencyInsight --dependency snakeyaml --configuration compileClasspath

// worked recently
gradle etl-core-app:dependencyInsight --dependency databind

Modules

subprojects vs allprojects

key difference between "subprojects" and "allprojects" is that "subprojects" only applies the settings to the direct subprojects of the current project, while "allprojects" applies the settings to the current project and all of its subprojects.

Build lifecycle

During the configuration phase, Gradle finds the build script(s) in the root and subproject directories.

Version catalog

Under the covers the testImplementation and implementation configurations form an inheritance hierarchy by calling the method

as a producer, to expose artifacts and their dependencies for consumption by other projects (such consumable configurations usually represent the the producer offers to its consumers)

Great article about which kind of modules can exist in the application.

Visualise modules.

When a build script, build.gradle(.kts), is found, Gradle configures a object.

The purpose of the object is to create a collection of objects, apply plugins, and retrieve dependencies.

🟢
Configuration.extendsFrom(org.gradle.api.artifacts.Configuration[])
Resolvable and consumable configurations
variants
Good article with explanation
LINK
LINK
Tool_1
Tool_2
Project
Project
Task
gradle docs
Great official userguide with walk through examples
LINK
configurations
LINK
Java plugin - main source set dependency configurations
Java plugin - test source set dependency configurations