Better check when to apply old syntax for configuration (KT-28513, KT-22571)
^KT-28513 Fixed
This commit is contained in:
+18
-4
@@ -23,6 +23,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.idea.util.module
|
||||
import org.jetbrains.plugins.gradle.settings.GradleSettings
|
||||
|
||||
@@ -66,15 +67,28 @@ interface GradleBuildScriptManipulator<out Psi : PsiFile> {
|
||||
fun addResolutionStrategy(pluginId: String)
|
||||
}
|
||||
|
||||
fun fetchGradleVersion(psiFile: PsiFile): GradleVersion {
|
||||
return gradleVersionFromFile(psiFile) ?: GradleVersion.current()
|
||||
}
|
||||
|
||||
private fun gradleVersionFromFile(psiFile: PsiFile): GradleVersion? {
|
||||
val module = psiFile.module ?: return null
|
||||
val path = ExternalSystemApiUtil.getExternalProjectPath(module) ?: return null
|
||||
return GradleSettings.getInstance(module.project).getLinkedProjectSettings(path)?.resolveGradleVersion()
|
||||
}
|
||||
|
||||
val MIN_GRADLE_VERSION_FOR_NEW_PLUGIN_SYNTAX = GradleVersion.version("4.4")
|
||||
|
||||
fun GradleBuildScriptManipulator<*>.useNewSyntax(kotlinPluginName: String): Boolean {
|
||||
if (!preferNewSyntax) return false
|
||||
|
||||
val module = scriptFile.module ?: return false
|
||||
val path = ExternalSystemApiUtil.getExternalProjectPath(module) ?: return false
|
||||
val gradleVersion = GradleSettings.getInstance(module.project).getLinkedProjectSettings(path)?.resolveGradleVersion() ?: return false
|
||||
val gradleVersion = fetchGradleVersion(scriptFile)
|
||||
if (gradleVersion < MIN_GRADLE_VERSION_FOR_NEW_PLUGIN_SYNTAX) return false
|
||||
|
||||
return !isConfiguredWithOldSyntax(kotlinPluginName)
|
||||
if (isConfiguredWithOldSyntax(kotlinPluginName)) return false
|
||||
|
||||
val fileText = runReadAction { scriptFile.text }
|
||||
val hasOldApply = fileText.contains("apply plugin:")
|
||||
|
||||
return !hasOldApply
|
||||
}
|
||||
+24
-2
@@ -22,6 +22,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.gradle.util.GradleVersion
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.plugins.gradle.frameworkSupport.BuildScriptDataBuilder
|
||||
|
||||
interface GradleBuildScriptManipulator<out Psi : PsiFile> {
|
||||
@@ -64,8 +65,29 @@ interface GradleBuildScriptManipulator<out Psi : PsiFile> {
|
||||
fun addResolutionStrategy(pluginId: String)
|
||||
}
|
||||
|
||||
fun fetchGradleVersion(psiFile: PsiFile): GradleVersion {
|
||||
return gradleVersionFromFile(psiFile) ?: GradleVersion.current()
|
||||
}
|
||||
|
||||
private fun gradleVersionFromFile(psiFile: PsiFile): GradleVersion? {
|
||||
return null
|
||||
}
|
||||
|
||||
val MIN_GRADLE_VERSION_FOR_NEW_PLUGIN_SYNTAX = GradleVersion.version("4.4")
|
||||
|
||||
// Kept for compatibility reasons (pre-181.3 IDEAs)
|
||||
fun GradleBuildScriptManipulator<*>.useNewSyntax(kotlinPluginName: String) = false
|
||||
val BuildScriptDataBuilder.gradleVersion get() = GradleVersion.version("0.0")
|
||||
val BuildScriptDataBuilder.gradleVersion get() = GradleVersion.version("0.0")
|
||||
|
||||
fun GradleBuildScriptManipulator<*>.useNewSyntax(kotlinPluginName: String): Boolean {
|
||||
if (!preferNewSyntax) return false
|
||||
|
||||
val gradleVersion = fetchGradleVersion(scriptFile)
|
||||
if (gradleVersion < MIN_GRADLE_VERSION_FOR_NEW_PLUGIN_SYNTAX) return false
|
||||
|
||||
if (isConfiguredWithOldSyntax(kotlinPluginName)) return false
|
||||
|
||||
val fileText = runReadAction { scriptFile.text }
|
||||
val hasOldApply = fileText.contains("apply plugin:")
|
||||
|
||||
return !hasOldApply
|
||||
}
|
||||
@@ -1,19 +1,11 @@
|
||||
// VERSION: $VERSION$
|
||||
buildscript {
|
||||
ext.kotlin_version = '$VERSION$'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
plugins {
|
||||
id 'org.jetbrains.kotlin.jvm' version '$VERSION$'
|
||||
}
|
||||
apply plugin: 'kotlin'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8"
|
||||
}
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
@@ -24,5 +16,5 @@ compileTestKotlin {
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
}
|
||||
}
|
||||
}// VERSION: $VERSION$
|
||||
// JDK: 1.8
|
||||
+4
-11
@@ -1,18 +1,11 @@
|
||||
plugins {
|
||||
id 'kotlin2js' version '$VERSION$'
|
||||
}
|
||||
version = '1.0'
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
buildscript {
|
||||
ext.kotlin_version = '$VERSION$'
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
apply plugin: 'kotlin2js'
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version"
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib-js"
|
||||
}
|
||||
|
||||
@@ -1,24 +1,9 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
val kotlin_version: String by extra
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "$VERSION$"
|
||||
repositories {
|
||||
maven { setUrl("https://dl.bintray.com/kotlin/kotlin-eap") }
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
apply {
|
||||
plugin("kotlin")
|
||||
kotlin("jvm") version "$VERSION$"
|
||||
}
|
||||
|
||||
application {
|
||||
@@ -32,7 +17,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
compile(kotlinModule("stdlib-jre8", kotlin_version))
|
||||
compile(kotlin("stdlib-jre8"))
|
||||
}
|
||||
|
||||
// VERSION: $VERSION$
|
||||
|
||||
@@ -1,23 +1,8 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
|
||||
val kotlin_version: String by extra
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "$VERSION$"
|
||||
repositories {
|
||||
maven { setUrl("https://dl.bintray.com/kotlin/kotlin-eap") }
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
apply {
|
||||
plugin("kotlin")
|
||||
kotlin("jvm") version "$VERSION$"
|
||||
}
|
||||
|
||||
application {
|
||||
@@ -31,7 +16,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
compile(kotlinModule("stdlib", kotlin_version))
|
||||
compile(kotlin("stdlib"))
|
||||
}
|
||||
|
||||
// VERSION: $VERSION$
|
||||
@@ -1,23 +1,9 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
val kotlin_version: String by extra
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "$VERSION$"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
application
|
||||
}
|
||||
apply {
|
||||
plugin("kotlin")
|
||||
kotlin("jvm") version "$VERSION$"
|
||||
}
|
||||
|
||||
application {
|
||||
@@ -30,7 +16,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
compile(kotlinModule("stdlib-jdk8", kotlin_version))
|
||||
compile(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
compileKotlin.kotlinOptions {
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
val kotlin_version: String by extra
|
||||
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "$VERSION$"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
@@ -17,6 +13,7 @@ buildscript {
|
||||
|
||||
plugins {
|
||||
application
|
||||
kotlin("jvm") version "$VERSION$"
|
||||
}
|
||||
|
||||
apply {
|
||||
@@ -33,7 +30,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
compile(kotlinModule("stdlib-jdk8", kotlin_version))
|
||||
compile(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
compileKotlin.kotlinOptions {
|
||||
|
||||
@@ -1,20 +1,9 @@
|
||||
import org.gradle.api.JavaVersion.VERSION_1_7
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||
|
||||
val kotlin_version: String by extra
|
||||
buildscript {
|
||||
var kotlin_version: String by extra
|
||||
kotlin_version = "$VERSION$"
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
dependencies {
|
||||
classpath(kotlinModule("gradle-plugin", kotlin_version))
|
||||
}
|
||||
}
|
||||
|
||||
plugins {
|
||||
application
|
||||
kotlin("jvm") version "$VERSION$"
|
||||
}
|
||||
|
||||
apply {
|
||||
@@ -31,7 +20,7 @@ repositories {
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.12")
|
||||
compile(kotlinModule("stdlib-jdk8", kotlin_version))
|
||||
compile(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
val compileKotlin: KotlinCompile by tasks
|
||||
compileKotlin.kotlinOptions {
|
||||
|
||||
Reference in New Issue
Block a user