Skip to content

Commit

Permalink
Search in all versions.properties, not just the first one #4830 (#4831)
Browse files Browse the repository at this point in the history
* Fix multiple versions.properties files #4830

* Improve build error when multiple Detekt versions are present

Co-authored-by: Tim Oltjenbruns <tim.oltjenbruns@softvision.com>
  • Loading branch information
timothyolt and Tim Oltjenbruns committed May 21, 2022
1 parent 5f491f1 commit ee2e9a0
Showing 1 changed file with 22 additions and 13 deletions.
Expand Up @@ -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."
)
}

0 comments on commit ee2e9a0

Please sign in to comment.