Don't add stdlib-jre7 or stdlib-jre8 dependencies when configuring Kotlin with pre-1.1 version
#KT-16401 Fixed
This commit is contained in:
+5
-5
@@ -74,17 +74,17 @@ public class KotlinAndroidGradleModuleConfigurator extends KotlinWithGradleConfi
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getRuntimeLibrary(@Nullable Sdk sdk) {
|
||||
if (sdk != null) {
|
||||
JavaSdkVersion version = JavaSdk.getInstance().getVersion(sdk);
|
||||
if (version != null && version.isAtLeast(JavaSdkVersion.JDK_1_8)) {
|
||||
public String getRuntimeLibrary(@Nullable Sdk sdk, @NotNull String version) {
|
||||
if (sdk != null && KotlinRuntimeLibraryUtilKt.hasJreSpecificRuntime(version)) {
|
||||
JavaSdkVersion sdkVersion = JavaSdk.getInstance().getVersion(sdk);
|
||||
if (sdkVersion != null && sdkVersion.isAtLeast(JavaSdkVersion.JDK_1_8)) {
|
||||
// Android dex can't convert our kotlin-stdlib-jre8 artifact, so use jre7 instead (KT-16530)
|
||||
return KotlinWithGradleConfigurator.Companion.getDependencySnippet(
|
||||
KotlinRuntimeLibraryUtilKt.getMAVEN_STDLIB_ID_JRE7());
|
||||
}
|
||||
}
|
||||
|
||||
return super.getRuntimeLibrary(sdk);
|
||||
return super.getRuntimeLibrary(sdk, version);
|
||||
}
|
||||
|
||||
KotlinAndroidGradleModuleConfigurator() {
|
||||
|
||||
+2
-3
@@ -21,7 +21,6 @@ import com.intellij.openapi.roots.ModuleRootManager
|
||||
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin
|
||||
import org.jetbrains.kotlin.idea.configuration.hasKotlinJvmRuntimeInScope
|
||||
import org.jetbrains.kotlin.idea.maven.PomFile
|
||||
import org.jetbrains.kotlin.idea.versions.MAVEN_STDLIB_ID
|
||||
import org.jetbrains.kotlin.idea.versions.getStdlibArtifactId
|
||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||
@@ -36,8 +35,8 @@ class KotlinJavaMavenConfigurator : KotlinMavenConfigurator(KotlinJavaMavenConfi
|
||||
return goalName == PomFile.KotlinGoals.Compile
|
||||
}
|
||||
|
||||
override fun getStdlibArtifactId(module: Module): String {
|
||||
return getStdlibArtifactId(ModuleRootManager.getInstance(module).sdk)
|
||||
override fun getStdlibArtifactId(module: Module, version: String): String {
|
||||
return getStdlibArtifactId(ModuleRootManager.getInstance(module).sdk, version)
|
||||
}
|
||||
|
||||
override fun createExecutions(pomFile: PomFile, kotlinPlugin: MavenDomPlugin, module: Module) {
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||
|
||||
class KotlinJavascriptMavenConfigurator : KotlinMavenConfigurator(null, false, KotlinJavascriptMavenConfigurator.NAME, KotlinJavascriptMavenConfigurator.PRESENTABLE_TEXT) {
|
||||
|
||||
override fun getStdlibArtifactId(module: Module) = MAVEN_JS_STDLIB_ID
|
||||
override fun getStdlibArtifactId(module: Module, version: String) = MAVEN_JS_STDLIB_ID
|
||||
|
||||
override fun isKotlinModule(module: Module): Boolean {
|
||||
return hasKotlinJsRuntimeInScope(module)
|
||||
|
||||
+2
-2
@@ -122,7 +122,7 @@ abstract class KotlinMavenConfigurator
|
||||
protected abstract fun isRelevantGoal(goalName: String): Boolean
|
||||
|
||||
protected abstract fun createExecutions(pomFile: PomFile, kotlinPlugin: MavenDomPlugin, module: Module)
|
||||
protected abstract fun getStdlibArtifactId(module: Module): String
|
||||
protected abstract fun getStdlibArtifactId(module: Module, version: String): String
|
||||
|
||||
fun changePomFile(
|
||||
module: Module,
|
||||
@@ -140,7 +140,7 @@ abstract class KotlinMavenConfigurator
|
||||
val pom = PomFile.forFileOrNull(file as XmlFile) ?: return
|
||||
pom.addProperty(KOTLIN_VERSION_PROPERTY, version)
|
||||
|
||||
pom.addDependency(MavenId(GROUP_ID, getStdlibArtifactId(module), "\${$KOTLIN_VERSION_PROPERTY}"), MavenArtifactScope.COMPILE, null, false, null)
|
||||
pom.addDependency(MavenId(GROUP_ID, getStdlibArtifactId(module, version), "\${$KOTLIN_VERSION_PROPERTY}"), MavenArtifactScope.COMPILE, null, false, null)
|
||||
if (testArtifactId != null) {
|
||||
pom.addDependency(MavenId(GROUP_ID, testArtifactId, "\${$KOTLIN_VERSION_PROPERTY}"), MavenArtifactScope.TEST, null, false, null)
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ fun hasKotlinFilesInSources(module: Module): Boolean {
|
||||
}
|
||||
|
||||
fun isSnapshot(version: String): Boolean {
|
||||
return version.contains("SNAPSHOT")
|
||||
return version.contains("SNAPSHOT", ignoreCase = true)
|
||||
}
|
||||
|
||||
fun isEap(version: String): Boolean {
|
||||
|
||||
+1
-1
@@ -88,7 +88,7 @@ class GradleKotlinJavaFrameworkSupportProvider : GradleKotlinFrameworkSupportPro
|
||||
override fun getPluginDefinition() = KotlinGradleModuleConfigurator.APPLY_KOTLIN
|
||||
|
||||
override fun getRuntimeLibrary(rootModel: ModifiableRootModel) =
|
||||
KotlinWithGradleConfigurator.getRuntimeLibraryForSdk(rootModel.sdk)
|
||||
KotlinWithGradleConfigurator.getRuntimeLibraryForSdk(rootModel.sdk, bundledRuntimeVersion())
|
||||
}
|
||||
|
||||
class GradleKotlinJSFrameworkSupportProvider : GradleKotlinFrameworkSupportProvider("KOTLIN_JS", "Kotlin (JavaScript)") {
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ class KotlinJsGradleModuleConfigurator : KotlinWithGradleConfigurator() {
|
||||
|
||||
override val applyPluginDirective: String = APPLY_KOTLIN_JS
|
||||
|
||||
override fun getDependencyDirective(sdk: Sdk?): String {
|
||||
override fun getDependencyDirective(sdk: Sdk?, version: String): String {
|
||||
return KotlinWithGradleConfigurator.getDependencySnippet(MAVEN_JS_STDLIB_ID)
|
||||
}
|
||||
|
||||
|
||||
@@ -92,27 +92,7 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
|
||||
project.executeCommand("Configure Kotlin") {
|
||||
val collector = createConfigureKotlinNotificationCollector(project)
|
||||
val changedFiles = HashSet<GroovyFile>()
|
||||
val projectGradleFile = getBuildGradleFile(project, getTopLevelProjectFilePath(project))
|
||||
if (projectGradleFile != null && canConfigureFile(projectGradleFile)) {
|
||||
val isModified = changeGradleFile(projectGradleFile, true, dialog.kotlinVersion, collector)
|
||||
if (isModified) {
|
||||
changedFiles.add(projectGradleFile)
|
||||
}
|
||||
}
|
||||
|
||||
for (module in dialog.modulesToConfigure) {
|
||||
val file = getBuildGradleFile(project, getModuleFilePath(module))
|
||||
if (file != null && canConfigureFile(file)) {
|
||||
val isModified = changeGradleFile(file, false, dialog.kotlinVersion, collector)
|
||||
if (isModified) {
|
||||
changedFiles.add(file)
|
||||
}
|
||||
}
|
||||
else {
|
||||
showErrorMessage(project, "Cannot find build.gradle file for module " + module.name)
|
||||
}
|
||||
}
|
||||
val changedFiles = configureWithVersion(project, dialog.modulesToConfigure, dialog.kotlinVersion, collector)
|
||||
|
||||
for (file in changedFiles) {
|
||||
OpenFileAction.openFile(file.virtualFile, project)
|
||||
@@ -121,6 +101,34 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
}
|
||||
}
|
||||
|
||||
fun configureWithVersion(project: Project,
|
||||
modulesToConfigure: List<Module>,
|
||||
kotlinVersion: String,
|
||||
collector: NotificationMessageCollector): HashSet<GroovyFile> {
|
||||
val changedFiles = HashSet<GroovyFile>()
|
||||
val projectGradleFile = getBuildGradleFile(project, getTopLevelProjectFilePath(project))
|
||||
if (projectGradleFile != null && canConfigureFile(projectGradleFile)) {
|
||||
val isModified = changeGradleFile(projectGradleFile, true, kotlinVersion, collector)
|
||||
if (isModified) {
|
||||
changedFiles.add(projectGradleFile)
|
||||
}
|
||||
}
|
||||
|
||||
for (module in modulesToConfigure) {
|
||||
val file = getBuildGradleFile(project, getModuleFilePath(module))
|
||||
if (file != null && canConfigureFile(file)) {
|
||||
val isModified = changeGradleFile(file, false, kotlinVersion, collector)
|
||||
if (isModified) {
|
||||
changedFiles.add(file)
|
||||
}
|
||||
}
|
||||
else {
|
||||
showErrorMessage(project, "Cannot find build.gradle file for module " + module.name)
|
||||
}
|
||||
}
|
||||
return changedFiles
|
||||
}
|
||||
|
||||
protected fun addElementsToModuleFile(file: GroovyFile, version: String): Boolean {
|
||||
var wasModified = false
|
||||
|
||||
@@ -149,12 +157,12 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
|
||||
val dependenciesBlock = getDependenciesBlock(file)
|
||||
val sdk = ModuleUtil.findModuleForPsiElement(file)?.let { ModuleRootManager.getInstance(it).sdk }
|
||||
wasModified = wasModified or addExpressionInBlockIfNeeded(getDependencyDirective(sdk), dependenciesBlock, false)
|
||||
wasModified = wasModified or addExpressionInBlockIfNeeded(getDependencyDirective(sdk, version), dependenciesBlock, false)
|
||||
|
||||
return wasModified
|
||||
}
|
||||
|
||||
protected open fun getDependencyDirective(sdk: Sdk?) = getRuntimeLibrary(sdk)
|
||||
protected open fun getDependencyDirective(sdk: Sdk?, version: String) = getRuntimeLibrary(sdk, version)
|
||||
|
||||
protected abstract val applyPluginDirective: String
|
||||
|
||||
@@ -193,8 +201,8 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
return isModified
|
||||
}
|
||||
|
||||
open fun getRuntimeLibrary(sdk: Sdk?): String {
|
||||
return getRuntimeLibraryForSdk(sdk)
|
||||
open fun getRuntimeLibrary(sdk: Sdk?, version: String): String {
|
||||
return getRuntimeLibraryForSdk(sdk, version)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -512,8 +520,8 @@ abstract class KotlinWithGradleConfigurator : KotlinProjectConfigurator {
|
||||
return addLastExpressionInBlockIfNeeded(snippet, repositoriesBlock)
|
||||
}
|
||||
|
||||
fun getRuntimeLibraryForSdk(sdk: Sdk?): String {
|
||||
return getDependencySnippet(getStdlibArtifactId(sdk))
|
||||
fun getRuntimeLibraryForSdk(sdk: Sdk?, version: String): String {
|
||||
return getDependencySnippet(getStdlibArtifactId(sdk, version))
|
||||
}
|
||||
|
||||
fun getDependencySnippet(artifactId: String) = "compile \"org.jetbrains.kotlin:$artifactId:\$kotlin_version\""
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.versions
|
||||
|
||||
import com.google.common.collect.Sets
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import com.intellij.openapi.module.ModuleUtil
|
||||
@@ -42,12 +40,10 @@ import com.intellij.util.PathUtil.getLocalPath
|
||||
import com.intellij.util.containers.MultiMap
|
||||
import com.intellij.util.indexing.FileBasedIndex
|
||||
import com.intellij.util.indexing.ScalarIndexExtension
|
||||
import com.intellij.util.text.VersionComparatorUtil
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.idea.KotlinPluginUtil
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinJavaModuleConfigurator
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinJsModuleConfigurator
|
||||
import org.jetbrains.kotlin.idea.configuration.createConfigureKotlinNotificationCollector
|
||||
import org.jetbrains.kotlin.idea.configuration.getConfiguratorByName
|
||||
import org.jetbrains.kotlin.idea.configuration.*
|
||||
import org.jetbrains.kotlin.idea.framework.*
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.idea.util.projectStructure.allModules
|
||||
@@ -297,7 +293,11 @@ fun hasKotlinJsKjsmFile(project: Project, scope: GlobalSearchScope): Boolean {
|
||||
}
|
||||
}
|
||||
|
||||
fun getStdlibArtifactId(sdk: Sdk?): String {
|
||||
fun getStdlibArtifactId(sdk: Sdk?, version: String): String {
|
||||
if (!hasJreSpecificRuntime(version)) {
|
||||
return MAVEN_STDLIB_ID
|
||||
}
|
||||
|
||||
val sdkVersion = sdk?.let { JavaSdk.getInstance().getVersion(it) }
|
||||
val artifactId = when (sdkVersion) {
|
||||
JavaSdkVersion.JDK_1_8, JavaSdkVersion.JDK_1_9 -> MAVEN_STDLIB_ID_JRE8
|
||||
@@ -307,6 +307,11 @@ fun getStdlibArtifactId(sdk: Sdk?): String {
|
||||
return artifactId
|
||||
}
|
||||
|
||||
fun hasJreSpecificRuntime(version: String): Boolean =
|
||||
VersionComparatorUtil.compare(version, "1.1.0") >= 0 ||
|
||||
isSnapshot(version) ||
|
||||
version == "default_version" /* for tests */
|
||||
|
||||
val MAVEN_STDLIB_ID = "kotlin-stdlib"
|
||||
val MAVEN_STDLIB_ID_JRE7 = "kotlin-stdlib-jre7"
|
||||
val MAVEN_STDLIB_ID_JRE8 = "kotlin-stdlib-jre8"
|
||||
|
||||
@@ -13,7 +13,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
buildscript {
|
||||
ext.kotlin_version = '$VERSION$'
|
||||
|
||||
@@ -13,7 +13,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
buildscript {
|
||||
ext.kotlin_version = '$VERSION$'
|
||||
|
||||
@@ -13,7 +13,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
testCompile group: 'junit', name: 'junit', version: '4.11'
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
}
|
||||
buildscript {
|
||||
ext.kotlin_version = '$VERSION$'
|
||||
|
||||
@@ -17,10 +17,13 @@
|
||||
package org.jetbrains.kotlin.idea.codeInsight.gradle
|
||||
|
||||
import com.intellij.openapi.extensions.Extensions
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
import com.intellij.openapi.fileEditor.impl.LoadTextUtil
|
||||
import com.intellij.openapi.module.ModuleManager
|
||||
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinStatus
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinGradleModuleConfigurator
|
||||
import org.jetbrains.kotlin.idea.configuration.KotlinProjectConfigurator
|
||||
import org.jetbrains.kotlin.idea.configuration.createConfigureKotlinNotificationCollector
|
||||
import org.jetbrains.kotlin.test.testFramework.runInEdtAndWait
|
||||
import org.jetbrains.kotlin.test.testFramework.runWriteAction
|
||||
import org.junit.Test
|
||||
@@ -63,4 +66,51 @@ class GradleConfiguratorTest : GradleImportingTestCase() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testConfigure10() {
|
||||
createProjectSubFile("settings.gradle", "include ':app'")
|
||||
val file = createProjectSubFile("app/build.gradle", """
|
||||
buildscript {
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
""".trimIndent())
|
||||
|
||||
importProject()
|
||||
|
||||
runInEdtAndWait {
|
||||
runWriteAction {
|
||||
val module = ModuleManager.getInstance(myProject).findModuleByName("app")!!
|
||||
val configurator = Extensions.findExtension(KotlinProjectConfigurator.EP_NAME,
|
||||
KotlinGradleModuleConfigurator::class.java)
|
||||
val collector = createConfigureKotlinNotificationCollector(myProject)
|
||||
configurator.configureWithVersion(myProject, listOf(module), "1.0.6", collector)
|
||||
|
||||
FileDocumentManager.getInstance().saveAllDocuments()
|
||||
val content = LoadTextUtil.loadText(file).toString()
|
||||
assertEquals("""
|
||||
buildscript {
|
||||
ext.kotlin_version = '1.0.6'
|
||||
repositories {
|
||||
jcenter()
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${"$"}kotlin_version"
|
||||
}
|
||||
}
|
||||
apply plugin: 'kotlin'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:${"$"}kotlin_version"
|
||||
}
|
||||
""".trimIndent(), content)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user