Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Dependency Management in Gradle 5 and Beyond

Dependency Management in Gradle 5 and Beyond

"The Java ecosystem allows developers to profit from a large pool of reusable libraries. Traditionally, the platform-independence of Java always made it easy to publish and share ready-to-use libraries. As Kotlin and Android developers, we also profit from this existing catalogue of libraries. However, new challenges for dealing with dependencies in the JVM world emerged over the past years, as software systems grew further in complexity and new platforms, such as Kotlin or Android, emerged.
Dependency management is one of the major functionalities of the Gradle Build Tool.
Gradle 5 offers a number of new stable features to support developers in managing dependencies – and more can be expected soon."

by Jendrik Johannes
presented on February 20, 2019 @codecentric

Kotlin User Group Hamburg

February 20, 2019
Tweet

More Decks by Kotlin User Group Hamburg

Other Decks in Programming

Transcript

  1. Chapter 1: Versioning of Software Components Chapter 2: Different Variants

    of Software Components Chapter 3: Dealing with an imperfect World
  2. Chapter 1: Versioning of Software Components Chapter 2: Different Variants

    of Software Components Chapter 3: Dealing with an imperfect World
  3. PRODUCER CONSUMER REPOSITORY push software component component metadata pull component

    metadata software component NULL 8 FUFFZEHN // BANK SantaSoft " !
  4. XMasTree by SantaSoft Open-source out-of-the-box Christmas trees for Java! From

    Christmas tree lovers for Christmas tree lovers! Maven dependencies { // just add your tree... implementation(“com.santasoft.xmastree:tree-swing:1.0”) // ...and decorate it as you like implementation(“com.santasoft.xmastree:lights-swing:1.0”) } Gradle // inject it in your UI code com.santasoft.xmastree.Tree.compose(container)
  5. XMasTree by SantaSoft Open-source out-of-the-box Christmas trees for Java! From

    Christmas tree lovers for Christmas tree lovers! Maven dependencies { // just add your tree... implementation(“com.santasoft.xmastree:tree-swing:2.0”) // ...and decorate it as you like implementation(“com.santasoft.xmastree:lights-swing:2.0”) } Gradle // inject it in your UI code com.santasoft.xmastree.Tree.compose(container) 2.0 W ITH FLASHY LIGHTS!
  6. Why did the Christmas tree crash? tree:1.0 lights:1.0 ornaments:1.0 train:1.0

    tree:2.0 lights:2.0 ornaments:2.0 train:2.0 component repository
  7. component repository Why did the Christmas tree crash? tree:1.0 lights:1.0

    null8fuffzehn-desktop ornaments:1.0 train:1.0 tree:2.0 lights:2.0 ornaments:2.0 train:2.0
  8. component repository Why did the Christmas tree crash? tree:1.0 lights:1.0

    null8fuffzehn-desktop ornaments:1.0 train:1.0 tree:2.0 lights:2.0 ornaments:2.0 train:2.0
  9. component repository Why did the Christmas tree crash? tree:1.0 lights:1.0

    null8fuffzehn-desktop ornaments:1.0 train:1.0 tree:2.0 lights:2.0 ornaments:2.0 train:2.0
  10. component repository Why did the Christmas tree crash? tree:1.0 lights:1.0

    null8fuffzehn-desktop ornaments:1.0 train:1.0 tree:2.0 lights:2.0 ornaments:2.0 train:2.0
  11. component repository Why did the Christmas tree crash? tree:1.0 lights:1.0

    null8fuffzehn-desktop ornaments:1.0 train:1.0 tree:2.0 lights:2.0 ornaments:2.0 train:2.0
  12. component repository Why did the Christmas tree crash? tree:1.0 lights:1.0

    null8fuffzehn-desktop ornaments:1.0 train:1.0 tree:2.0 lights:2.0 ornaments:2.0 train:2.0 conflict !
  13. component repository Dependency Constraints tree:1.0 lights:1.0 ornaments:1.0 train:1.0 tree:2.0 lights:2.0

    ornaments:2.0 train:2.0 depends-on (requires + constraints) constraints
  14. component repository Dependency Constraints save Christmas tree:1.0 lights:1.0 ornaments:1.0 train:1.0

    tree:2.0 lights:2.0 ornaments:2.0 train:2.0 depends-on (requires + constraints) constraints null8fuffzehn-desktop
  15. component repository Dependency Constraints save Christmas tree:1.0 lights:1.0 ornaments:1.0 train:1.0

    tree:2.0 lights:2.0 ornaments:2.0 train:2.0 depends-on (requires + constraints) constraints null8fuffzehn-desktop
  16. com.santasoft.xmastree:tree-swing:2.0 github.com/gradle/gradle/blob/master/subprojects/docs/src/ docs/design/gradle-module-metadata-specification.md { "component": { "group": "com.santasoft.xmastree", "module": "tree-swing",

    "version": "2.0", }, ... "dependencyConstraints": [ { "group": "com.santasoft.xmastree", "module": "lights-swing", "version": { "requires": "2.0" } }, { "group": "com.santasoft.xmastree", "module": "ornaments-swing", "version": { "requires": "2.0" } }, { "group": "com.santasoft.xmastree", "module": "train-swing", "version": { "requires": "2.0" } } ], ... } component repository — tree-swing-2.0.jar — tree-swing-2.0.pom — tree-swing-2.0.module
  17. Chapter 1: Versioning of Software Components Chapter 2: Different Variants

    of Software Components Chapter 3: Dealing with an imperfect World
  18. Gradle_Android XMasTree by SantaSoft Open-source out-of-the-box Christmas trees for Java!

    From Christmas tree lovers for Christmas tree lovers! Maven dependencies { // just add your tree... implementation(“com.santasoft.xmastree:tree-swing:2.0”) // ...and decorate it as you like implementation(“com.santasoft.xmastree:lights-swing:2.0”) } Gradle // inject it in your UI code com.santasoft.xmastree.Tree.compose(container) NOW ALSO FOR ANDROID! 2.0 W ITH FLASHY LIGHTS!
  19. Gradle XMasTree by SantaSoft Open-source out-of-the-box Christmas trees for Java!

    From Christmas tree lovers for Christmas tree lovers! Maven dependencies { // just add your tree... implementation(“com.santasoft.xmastree:tree-android:2.0”) // ...and decorate it as you like implementation(“com.santasoft.xmastree:lights-android:2.0”) } // inject it in your UI code com.santasoft.xmastree.Tree.compose(container) Gradle_Android NOW ALSO FOR ANDROID! 2.0 W ITH FLASHY LIGHTS!
  20. component repository Modeling Platforms as Variants tree-swing lights-swing null8fuffzehn-desktop ornaments-swing

    train-swing tree-android lights-android null8fuffzehn-android ornaments-android train-android
  21. component repository Modeling Platforms as Variants tree-swing lights-swing ornaments-swing train-swing

    tree-android lights-android ornaments-android train-android null8fuffzehn-shared null8fuffzehn-desktop null8fuffzehn-android
  22. component repository Modeling Platforms as Variants tree-swing lights-swing ornaments-swing train-swing

    tree-android lights-android ornaments-android train-android null8fuffzehn-shared null8fuffzehn-desktop null8fuffzehn-android tree lights ornaments train variant ui-framework = swing variant ui-framework = android ui-framework = swing ui-framework = android
  23. component repository Modeling Platforms as Variants tree-swing lights-swing ornaments-swing train-swing

    tree-android lights-android ornaments-android train-android null8fuffzehn-shared null8fuffzehn-desktop null8fuffzehn-android tree lights ornaments train variant ui-framework = swing variant ui-framework = android ui-framework = swing ui-framework = android
  24. component repository Modeling Platforms as Variants tree-swing lights-swing ornaments-swing train-swing

    tree-android lights-android ornaments-android train-android null8fuffzehn-shared null8fuffzehn-desktop null8fuffzehn-android tree lights ornaments train variant ui-framework = swing variant ui-framework = android ui-framework = swing ui-framework = android
  25. Gradle_Android Gradle XMasTree by SantaSoft Open-source out-of-the-box Christmas trees for

    Java! From Christmas tree lovers for Christmas tree lovers! Maven // configure your tree dependencies { implementation(“com.santasoft.xmastree:lights”) } // choose your variant configurations.all { attributes { attribute(“ui-framework”, “android”) } } // inject it in your UI code com.santasoft.xmastree.Tree.compose(container) NOW ALSO FOR ANDROID! 2.0 W ITH FLASHY LIGHTS! NOW W ITH VARIANT SUPPORT! Gradle_Variants
  26. com.santasoft.xmastree:tree:2.0 github.com/gradle/gradle/blob/master/subprojects/docs/src/ docs/design/gradle-module-metadata-specification.md { "component": { "group": "com.santasoft.xmastree", "module": "tree",

    "version": "2.0", "attributes": { "org.gradle.status": "release" } }, "variants": [ { "name": "swing-api", "attributes": { "org.gradle.usage": "java-api", "ui-framework": "swing" }, "available-at": { "url": "../../tree-swing/2.0/tree-swing-2.0.module", "group": "com.santasoft.xmastree", "module": "tree-swing", "version": "2.0" } }, { "name": "android-api", "attributes": { "org.gradle.usage": "java-api", "ui-framework": "android" }, "available-at": { "url": "../../tree-swing/2.0/tree-android-2.0.module", "group": "com.santasoft.xmastree", "module": "tree-android", "version": "2.0" } } ] ... } component repository — tree-swing-2.0.module
  27. Chapter 1: Versioning of Software Components Chapter 2: Different Variants

    of Software Components Chapter 3: Dealing with the imperfect World
  28. PRODUCER CONSUMER REPOSITORY push software component component metadata pull component

    metadata software component NULL 8 FUFFZEHN // BANK SantaSoft " ! What if the consumer has a different opinion than the producer?
  29. component repository tree lights ornaments train What if the consumer

    has a different opinion than the producer? null8fuffzehn-desktop
  30. component repository tree lights ornaments train What if the consumer

    has a different opinion than the producer? null8fuffzehn-desktop Component Metadata Rule
  31. Gradle_Variants Gradle_Android Gradle XMasTree by SantaSoft Open-source out-of-the-box Christmas trees

    for Java! From Christmas tree lovers for Christmas tree lovers! Maven // configure your tree dependencies { implementation(“com.santasoft.xmastree:lights”) } // choose your variant configurations.all { attributes { attribute(“ui-framework”, “gif”) } } // inject it in your UI code com.santasoft.xmastree.Tree.compose(container) NOW ALSO FOR ANDROID! 2.0 W ITH FLASHY LIGHTS! NOW W ITH VARIANT SUPPORT! NOW ALSO AS FLASHY GIF VARIANT! GIF
  32. component repository tree-swing lights-swing ornaments-swing train-swing tree-gif lights-gif null8fuffzehn-shared null8fuffzehn-gif

    tree lights ornaments train variant ui-framework = swing variant ui-framework = gif ui-framework = gif What if the producer “forgot” an important variant?
  33. component repository tree-swing lights-swing ornaments-swing train-swing tree-gif lights-gif null8fuffzehn-shared null8fuffzehn-gif

    tree lights ornaments train variant ui-framework = swing variant ui-framework = gif ui-framework = gif X What if the producer “forgot” an important variant?
  34. component repository tree-swing lights-swing ornaments-swing train-swing tree-gif lights-gif null8fuffzehn-shared null8fuffzehn-gif

    tree lights ornaments train variant ui-framework = swing variant ui-framework = gif ui-framework = gif What if the producer “forgot” an important variant? train-gif transformed into
  35. Chapter 1: Versioning of Software Components Chapter 2: Different Variants

    of Software Components Chapter 3: Dealing with the imperfect World …and in the real world?
  36. Gradle Summit 2017
 Dependencies, distributed code and engineering velocity
 -

    Mike McGarr, Netflix https://www.youtube.com/watch?v=k_mPS_1JpXM
  37. Dependency Constraints dependencies { implementation("org.apache.httpcomponents:httpclient") constraints { implementation("org.apache.httpcomponents:httpclient:4.5.3") { because("previous

    versions have a bug impacting this application") } implementation("commons-codec:commons-codec:1.11") { because("version 1.9 pulled from httpclient has bugs affecting this application") } } }
  38. BOM/Platform support dependencies { // import a BOM implementation(platform( “org.springframework.boot:spring-boot-dependencies:1.5.8.RELEASE"))

    // define dependencies without versions implementation("com.google.code.gson:gson") implementation("dom4j:dom4j") }
  39. dependencies { // get recommended versions from the platform project

    api(platform(project(":platform"))) // no version required api("commons-httpclient:commons-httpclient") } Java Platform Plugin consumer plugins { `java-platform` } dependencies { constraints { // Platform declares some versions of libraries used in subprojects api("commons-httpclient:commons-httpclient:3.1") api("org.apache.commons:commons-lang3:3.8.1") } } producer
  40. (New) Maven Publish Plugin publishing { publications { create<MavenPublication>("maven") {

    groupId = "org.gradle.sample" artifactId = "project1-sample" version = "1.1" from(components["java"]) } } } enableFeaturePreview("GRADLE_METADATA") settings.gradle.kts