Skip to content

Instantly share code, notes, and snippets.

@lordcodes
Created November 28, 2020 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lordcodes/64147f4c72ede78db43868f8a6120cfa to your computer and use it in GitHub Desktop.
Save lordcodes/64147f4c72ede78db43868f8a6120cfa to your computer and use it in GitHub Desktop.
Brief demo of using a platform module to constrain dependency versions
dependencies {
implementation(enforcedPlatform(project(":dependency-constraints")))
implementation("org.jetbrains.kotlin:kotlin-stdlib")
implementation("androidx.lifecycle:lifecycle-livedata-ktx")
implementation("io.coil-kt:coil")
}
plugins {
id("java-platform")
id("maven-publish")
}
javaPlatform {
allowDependencies()
}
dependencies {
api(enforcedPlatform("org.jetbrains.kotlin:kotlin-bom:1.4.20"))
constraints {
api("androidx.lifecycle:lifecycle-livedata-ktx:2.3.0-beta01")
api("io.coil-kt:coil:1.0.0")
}
}
publishing {
publications {
create<MavenPublication>("getBusyPlatform") {
from(components["javaPlatform"])
}
}
}
include("dependency-constraints")
@jraska
Copy link

jraska commented Nov 30, 2020

Thanks a lot for the insights :)

it disables regular dependency declarations as that is usually a bug

Doesn't this allow it back?

javaPlatform {
    allowDependencies()
}

This or BOMs themselves in general do not bring any jar?
So this: api(enforcedPlatform("org.jetbrains.kotlin:kotlin-bom:1.4.20")) does add zero dependencies? :)

When it comes to an article I think my idea or name would be - "Avoid dependency hell with a power of BOM and Gradle constraints" or something like that :D

@lordcodes
Copy link
Author

Exactly I added 'allowDependencies()' in order to allow the platform to specify real dependencies so that I could specify the BOMs for other frameworks.

Also, yes adding a platform for the kotlin-bom simply brings in constraints on the versions. So that you can simply specify Kotlin dependencies throughout your project without the version, then update the Kotlin version only on the BOM.

Haha amazing. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment