dagger.hilt.android.plugin.util.SimpleAGPVersion.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hilt-android-gradle-plugin Show documentation
Show all versions of hilt-android-gradle-plugin Show documentation
A fast dependency injector for Android and Java.
package dagger.hilt.android.plugin.util
import com.android.Version
/**
* Simple Android Gradle Plugin version class since there is no public API one. b/175816217
*/
internal data class SimpleAGPVersion(
val major: Int,
val minor: Int,
) : Comparable {
override fun compareTo(other: SimpleAGPVersion): Int {
return compareValuesBy(
this,
other,
compareBy(SimpleAGPVersion::major).thenBy(SimpleAGPVersion::minor)
) { it }
}
companion object {
val ANDROID_GRADLE_PLUGIN_VERSION by lazy { parse(Version.ANDROID_GRADLE_PLUGIN_VERSION) }
fun parse(version: String?) =
tryParse(version) ?: error("Unable to parse AGP version: $version")
private fun tryParse(version: String?): SimpleAGPVersion? {
if (version == null) {
return null
}
val parts = version.split('.')
if (parts.size == 1) {
return SimpleAGPVersion(parts[0].toInt(), 0)
}
return SimpleAGPVersion(parts[0].toInt(), parts[1].toInt())
}
}
}