diff --git a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/inspections/gradle/DifferentStdlibGradleVersionInspection.kt b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/inspections/gradle/DifferentStdlibGradleVersionInspection.kt index 42a10c2ac91..0c17b85659c 100644 --- a/idea/idea-gradle/src/org/jetbrains/kotlin/idea/inspections/gradle/DifferentStdlibGradleVersionInspection.kt +++ b/idea/idea-gradle/src/org/jetbrains/kotlin/idea/inspections/gradle/DifferentStdlibGradleVersionInspection.kt @@ -68,7 +68,11 @@ class DifferentStdlibGradleVersionInspection : GradleBaseInspection() { companion object { private fun findLibraryStatement(closure: GrClosableBlock, libraryGroup: String, libraryIds: List): GrCallExpression? { return GradleHeuristicHelper.findStatementWithPrefixes(closure, PRODUCTION_DEPENDENCY_STATEMENTS).firstOrNull { statement -> - libraryIds.any { it in statement.text } && statement.text.contains(libraryGroup) + libraryIds.any { + val index = statement.text.indexOf(it) + // This prevents detecting kotlin-stdlib inside kotlin-stdlib-common, -jdk8, etc. + index != -1 && statement.text.getOrNull(index + it.length) != '-' + } && statement.text.contains(libraryGroup) } } diff --git a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleInspectionTest.kt b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleInspectionTest.kt index 23051b48ca3..bd39763ef4d 100644 --- a/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleInspectionTest.kt +++ b/idea/idea-gradle/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleInspectionTest.kt @@ -168,7 +168,6 @@ class GradleInspectionTest : GradleImportingTestCase() { Assert.assertEquals("Plugin version (1.1.0-beta-17) is not the same as library version (1.1.0-beta-22)", problems.single()) } - @Test fun testDifferentStdlibGradleVersionWithVariables() { createProjectSubFile( @@ -383,6 +382,76 @@ class GradleInspectionTest : GradleImportingTestCase() { ) } + @Test + fun testNoDifferentStdlibCommonGradleVersion() { + val localFile = createProjectSubFile( + "build.gradle", """ + group 'Again' + version '1.0-SNAPSHOT' + + buildscript { + repositories { + mavenCentral() + maven { + url 'http://dl.bintray.com/kotlin/kotlin-eap' + } + } + + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.40-eap-51") + } + } + + apply plugin: 'kotlin-platform-common' + + dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib-common:1.2.40-eap-51" + } + """ + ) + importProject() + + val tool = DifferentStdlibGradleVersionInspection() + val problems = getInspectionResult(tool, localFile) + + Assert.assertTrue(problems.toString(), problems.isEmpty()) + } + + @Test + fun testNoDifferentStdlibJdk7GradleVersion() { + val localFile = createProjectSubFile( + "build.gradle", """ + group 'Again' + version '1.0-SNAPSHOT' + + buildscript { + repositories { + mavenCentral() + maven { + url 'http://dl.bintray.com/kotlin/kotlin-eap' + } + } + + dependencies { + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.40-eap-51") + } + } + + apply plugin: 'kotlin' + + dependencies { + compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.40-eap-51" + } + """ + ) + importProject() + + val tool = DifferentStdlibGradleVersionInspection() + val problems = getInspectionResult(tool, localFile) + + Assert.assertTrue(problems.toString(), problems.isEmpty()) + } + @Test fun testObsoleteCoroutinesUsage() { val localFile = createProjectSubFile( @@ -428,7 +497,7 @@ class GradleInspectionTest : GradleImportingTestCase() { ) } - fun getInspectionResult(tool: LocalInspectionTool, file: VirtualFile): List { + private fun getInspectionResult(tool: LocalInspectionTool, file: VirtualFile): List { val resultRef = Ref>() invokeTestRunnable { val presentation = runInspection(tool, myProject, listOf(file))