mirror of
https://github.com/jlengrand/detekt.git
synced 2026-03-10 08:11:23 +00:00
* 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:
@@ -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."
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user