mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Fix warnings in dependency_version_checker.gradle.kts (#148699)
Newer Gradle/AGP versions include the following warnings: ``` w: file:///Users/goderbauer/dev/flutter/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:107:40: Variable 'agpVersion' initializer is redundant w: file:///Users/goderbauer/dev/flutter/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:108:40: Variable 'kgpVersion' initializer is redundant w: file:///Users/goderbauer/dev/flutter/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:143:28: Parameter 'project' is never used w: file:///Users/goderbauer/dev/flutter/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:152:40: Variable 'agpVersion' initializer is redundant w: file:///Users/goderbauer/dev/flutter/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:167:55: 'Version' is deprecated. Deprecated in Java w: file:///Users/goderbauer/dev/flutter/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:195:56: Unnecessary non-null assertion (!!) on a non-null receiver of type Any w: file:///Users/goderbauer/dev/flutter/packages/flutter_tools/gradle/src/main/kotlin/dependency_version_checker.gradle.kts:344:28: The corresponding parameter in the supertype 'Comparable' is named 'other'. This may cause problems when calling this function with named arguments. ``` These also get printed out to the CLI, so they are somewhat annoying. Fixes all of the warnings, except for `'Version' is deprecated. Deprecated in Java`, which gets suppressed (we are intentionally using the deprecated `Version`, to help support older versions of AGP that use that deprecated class).
This commit is contained in:
parent
1fa6f56b48
commit
24979ab2c5
@ -104,11 +104,11 @@ class DependencyVersionChecker {
|
||||
* we treat it as within the range for the purpose of this check.
|
||||
*/
|
||||
fun checkDependencyVersions(project: Project) {
|
||||
var agpVersion: Version? = null
|
||||
var kgpVersion: Version? = null
|
||||
var agpVersion: Version?
|
||||
var kgpVersion: Version?
|
||||
|
||||
checkGradleVersion(getGradleVersion(project), project)
|
||||
checkJavaVersion(getJavaVersion(project), project)
|
||||
checkJavaVersion(getJavaVersion(), project)
|
||||
agpVersion = getAGPVersion(project)
|
||||
if (agpVersion != null) {
|
||||
checkAGPVersion(agpVersion, project)
|
||||
@ -140,7 +140,7 @@ class DependencyVersionChecker {
|
||||
}
|
||||
|
||||
// https://docs.gradle.org/current/kotlin-dsl/gradle/org.gradle.api/-java-version/index.html#-1790786897%2FFunctions%2F-1793262594
|
||||
fun getJavaVersion(project: Project): JavaVersion {
|
||||
fun getJavaVersion(): JavaVersion {
|
||||
return JavaVersion.current()
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ class DependencyVersionChecker {
|
||||
fun getAGPVersion(project: Project): Version? {
|
||||
val agpPluginName: String = "com.android.base"
|
||||
val agpVersionFieldName: String = "ANDROID_GRADLE_PLUGIN_VERSION"
|
||||
var agpVersion: Version? = null
|
||||
var agpVersion: Version?
|
||||
try {
|
||||
agpVersion =
|
||||
Version.fromString(
|
||||
@ -161,6 +161,7 @@ class DependencyVersionChecker {
|
||||
} catch (ignored: ClassNotFoundException) {
|
||||
// Use deprecated Version class as it exists in older AGP (com.android.Version) does
|
||||
// not exist in those versions.
|
||||
@Suppress("deprecation")
|
||||
agpVersion =
|
||||
Version.fromString(
|
||||
project.plugins.getPlugin(agpPluginName)::class.java.classLoader.loadClass(
|
||||
@ -192,7 +193,7 @@ class DependencyVersionChecker {
|
||||
if (versionString == null) {
|
||||
return null
|
||||
} else {
|
||||
return Version.fromString(versionString!! as String)
|
||||
return Version.fromString(versionString as String)
|
||||
}
|
||||
}
|
||||
|
||||
@ -341,15 +342,15 @@ class Version(val major: Int, val minor: Int, val patch: Int) : Comparable<Versi
|
||||
}
|
||||
}
|
||||
|
||||
override fun compareTo(otherVersion: Version): Int {
|
||||
if (major != otherVersion.major) {
|
||||
return major - otherVersion.major
|
||||
override fun compareTo(other: Version): Int {
|
||||
if (major != other.major) {
|
||||
return major - other.major
|
||||
}
|
||||
if (minor != otherVersion.minor) {
|
||||
return minor - otherVersion.minor
|
||||
if (minor != other.minor) {
|
||||
return minor - other.minor
|
||||
}
|
||||
if (patch != otherVersion.patch) {
|
||||
return patch - otherVersion.patch
|
||||
if (patch != other.patch) {
|
||||
return patch - other.patch
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user