diff --git a/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/extensions/DetektExtension.kt b/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/extensions/DetektExtension.kt index 7b8937f0ef8..cd5e24e1d66 100644 --- a/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/extensions/DetektExtension.kt +++ b/detekt-gradle-plugin/src/main/kotlin/io/gitlab/arturbosch/detekt/extensions/DetektExtension.kt @@ -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." + ) }