Search in all versions.properties, not just the first one #4830 (#4831)

* Fix multiple versions.properties files #4830

* Improve build error when multiple Detekt versions are present

Co-authored-by: Tim Oltjenbruns <tim.oltjenbruns@softvision.com>
This commit is contained in:
Tim Oltjenbruns
2022-05-21 07:23:58 -04:00
committed by GitHub
parent 5f491f1da6
commit ee2e9a07b2

View File

@@ -107,17 +107,26 @@ open class DetektExtension @Inject constructor(objects: ObjectFactory) : CodeQua
}
}
internal fun loadDetektVersion(classLoader: ClassLoader): String = Properties().run {
val inputStream = classLoader.getResource("versions.properties")!!.openConnection()
/*
* Due to https://bugs.openjdk.java.net/browse/JDK-6947916 and https://bugs.openjdk.java.net/browse/JDK-8155607,
* it is necessary to disallow caches to maintain stability on JDK 8 and 11 (and possibly more).
* Otherwise, simultaneous invocations of Detekt in the same VM can fail spuriously. A similar bug is referenced in
* https://github.com/detekt/detekt/issues/3396. The performance regression is likely unnoticeable.
* Due to https://github.com/detekt/detekt/issues/4332 it is included for all JDKs.
*/
.apply { useCaches = false }
.getInputStream()
load(inputStream)
getProperty("detektVersion")
internal fun loadDetektVersion(classLoader: ClassLoader): String {
// Other Gradle plugins can also have a versions.properties.
val distinctVersions = classLoader.getResources("versions.properties").toList().mapNotNull { versions ->
Properties().run {
val inputStream = versions.openConnection()
/*
* Due to https://bugs.openjdk.java.net/browse/JDK-6947916 and https://bugs.openjdk.java.net/browse/JDK-8155607,
* it is necessary to disallow caches to maintain stability on JDK 8 and 11 (and possibly more).
* Otherwise, simultaneous invocations of Detekt in the same VM can fail spuriously. A similar bug is referenced in
* https://github.com/detekt/detekt/issues/3396. The performance regression is likely unnoticeable.
* Due to https://github.com/detekt/detekt/issues/4332 it is included for all JDKs.
*/
.apply { useCaches = false }
.getInputStream()
load(inputStream)
getProperty("detektVersion")
}
}.distinct()
return distinctVersions.singleOrNull() ?: error(
"You're importing two Detekt plugins which have different versions. " +
"(${distinctVersions.joinToString()}) Make sure to align the versions."
)
}