Configuring project with Maven adds kotlin-stdlib-jre7 or kotlin-stdlib-jre8 if the selected JDK is of a high enough version
#KT-15712 Fixed
This commit is contained in:
@@ -99,7 +99,7 @@ class PomFile(val xmlFile: XmlFile) {
|
|||||||
require(artifact.artifactId != null) { "artifactId shouldn't be null" }
|
require(artifact.artifactId != null) { "artifactId shouldn't be null" }
|
||||||
|
|
||||||
ensureDependencies()
|
ensureDependencies()
|
||||||
val versionless = artifact.withNoVersion()
|
val versionless = artifact.withNoVersion().withoutJreSuffix()
|
||||||
val dependency = domModel.dependencies.dependencies.firstOrNull { it.matches(versionless) } ?: domModel.dependencies.addDependency()
|
val dependency = domModel.dependencies.dependencies.firstOrNull { it.matches(versionless) } ?: domModel.dependencies.addDependency()
|
||||||
dependency.groupId.stringValue = artifact.groupId
|
dependency.groupId.stringValue = artifact.groupId
|
||||||
dependency.artifactId.stringValue = artifact.artifactId
|
dependency.artifactId.stringValue = artifact.artifactId
|
||||||
@@ -367,6 +367,7 @@ class PomFile(val xmlFile: XmlFile) {
|
|||||||
&& (artifact.version == null || version.stringValue == artifact.version)
|
&& (artifact.version == null || version.stringValue == artifact.version)
|
||||||
|
|
||||||
private fun MavenId.withNoVersion() = MavenId(groupId, artifactId, null)
|
private fun MavenId.withNoVersion() = MavenId(groupId, artifactId, null)
|
||||||
|
private fun MavenId.withoutJreSuffix() = MavenId(groupId, artifactId?.substringBeforeLast("-jre"), null)
|
||||||
|
|
||||||
private fun MavenDomElement.createChildTag(name: String, value: String? = null) = xmlTag.createChildTag(name, value)
|
private fun MavenDomElement.createChildTag(name: String, value: String? = null) = xmlTag.createChildTag(name, value)
|
||||||
private fun XmlTag.createChildTag(name: String, value: String? = null) = createChildTag(name, namespace, value, false)!!
|
private fun XmlTag.createChildTag(name: String, value: String? = null) = createChildTag(name, namespace, value, false)!!
|
||||||
|
|||||||
+7
-1
@@ -17,14 +17,16 @@
|
|||||||
package org.jetbrains.kotlin.idea.maven.configuration
|
package org.jetbrains.kotlin.idea.maven.configuration
|
||||||
|
|
||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.module.Module
|
||||||
|
import com.intellij.openapi.roots.ModuleRootManager
|
||||||
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin
|
import org.jetbrains.idea.maven.dom.model.MavenDomPlugin
|
||||||
import org.jetbrains.kotlin.idea.configuration.hasKotlinJvmRuntimeInScope
|
import org.jetbrains.kotlin.idea.configuration.hasKotlinJvmRuntimeInScope
|
||||||
import org.jetbrains.kotlin.idea.maven.PomFile
|
import org.jetbrains.kotlin.idea.maven.PomFile
|
||||||
import org.jetbrains.kotlin.idea.versions.MAVEN_STDLIB_ID
|
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.TargetPlatform
|
||||||
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
import org.jetbrains.kotlin.resolve.jvm.platform.JvmPlatform
|
||||||
|
|
||||||
class KotlinJavaMavenConfigurator : KotlinMavenConfigurator(MAVEN_STDLIB_ID, KotlinJavaMavenConfigurator.TEST_LIB_ID, false, KotlinJavaMavenConfigurator.NAME, KotlinJavaMavenConfigurator.PRESENTABLE_TEXT) {
|
class KotlinJavaMavenConfigurator : KotlinMavenConfigurator(KotlinJavaMavenConfigurator.TEST_LIB_ID, false, KotlinJavaMavenConfigurator.NAME, KotlinJavaMavenConfigurator.PRESENTABLE_TEXT) {
|
||||||
|
|
||||||
override fun isKotlinModule(module: Module): Boolean {
|
override fun isKotlinModule(module: Module): Boolean {
|
||||||
return hasKotlinJvmRuntimeInScope(module)
|
return hasKotlinJvmRuntimeInScope(module)
|
||||||
@@ -34,6 +36,10 @@ class KotlinJavaMavenConfigurator : KotlinMavenConfigurator(MAVEN_STDLIB_ID, Kot
|
|||||||
return goalName == PomFile.KotlinGoals.Compile
|
return goalName == PomFile.KotlinGoals.Compile
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getStdlibArtifactId(module: Module): String {
|
||||||
|
return getStdlibArtifactId(ModuleRootManager.getInstance(module).sdk)
|
||||||
|
}
|
||||||
|
|
||||||
override fun createExecutions(pomFile: PomFile, kotlinPlugin: MavenDomPlugin, module: Module) {
|
override fun createExecutions(pomFile: PomFile, kotlinPlugin: MavenDomPlugin, module: Module) {
|
||||||
createExecution(pomFile, kotlinPlugin, PomFile.DefaultPhases.Compile, PomFile.KotlinGoals.Compile, module, false)
|
createExecution(pomFile, kotlinPlugin, PomFile.DefaultPhases.Compile, PomFile.KotlinGoals.Compile, module, false)
|
||||||
createExecution(pomFile, kotlinPlugin, PomFile.DefaultPhases.TestCompile, PomFile.KotlinGoals.TestCompile, module, true)
|
createExecution(pomFile, kotlinPlugin, PomFile.DefaultPhases.TestCompile, PomFile.KotlinGoals.TestCompile, module, true)
|
||||||
|
|||||||
+3
-1
@@ -24,7 +24,9 @@ import org.jetbrains.kotlin.idea.versions.MAVEN_JS_STDLIB_ID
|
|||||||
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
import org.jetbrains.kotlin.js.resolve.JsPlatform
|
||||||
import org.jetbrains.kotlin.resolve.TargetPlatform
|
import org.jetbrains.kotlin.resolve.TargetPlatform
|
||||||
|
|
||||||
class KotlinJavascriptMavenConfigurator : KotlinMavenConfigurator(MAVEN_JS_STDLIB_ID, null, false, KotlinJavascriptMavenConfigurator.NAME, KotlinJavascriptMavenConfigurator.PRESENTABLE_TEXT) {
|
class KotlinJavascriptMavenConfigurator : KotlinMavenConfigurator(null, false, KotlinJavascriptMavenConfigurator.NAME, KotlinJavascriptMavenConfigurator.PRESENTABLE_TEXT) {
|
||||||
|
|
||||||
|
override fun getStdlibArtifactId(module: Module) = MAVEN_JS_STDLIB_ID
|
||||||
|
|
||||||
override fun isKotlinModule(module: Module): Boolean {
|
override fun isKotlinModule(module: Module): Boolean {
|
||||||
return hasKotlinJsRuntimeInScope(module)
|
return hasKotlinJsRuntimeInScope(module)
|
||||||
|
|||||||
+3
-3
@@ -43,8 +43,7 @@ import org.jetbrains.kotlin.idea.maven.excludeMavenChildrenModules
|
|||||||
import org.jetbrains.kotlin.idea.maven.kotlinPluginId
|
import org.jetbrains.kotlin.idea.maven.kotlinPluginId
|
||||||
|
|
||||||
abstract class KotlinMavenConfigurator
|
abstract class KotlinMavenConfigurator
|
||||||
protected constructor(private val stdlibArtifactId: String,
|
protected constructor(private val testArtifactId: String?,
|
||||||
private val testArtifactId: String?,
|
|
||||||
private val addJunit: Boolean,
|
private val addJunit: Boolean,
|
||||||
override val name: String,
|
override val name: String,
|
||||||
override val presentableText: String) : KotlinProjectConfigurator {
|
override val presentableText: String) : KotlinProjectConfigurator {
|
||||||
@@ -103,6 +102,7 @@ abstract class KotlinMavenConfigurator
|
|||||||
protected abstract fun isRelevantGoal(goalName: String): Boolean
|
protected abstract fun isRelevantGoal(goalName: String): Boolean
|
||||||
|
|
||||||
protected abstract fun createExecutions(pomFile: PomFile, kotlinPlugin: MavenDomPlugin, module: Module)
|
protected abstract fun createExecutions(pomFile: PomFile, kotlinPlugin: MavenDomPlugin, module: Module)
|
||||||
|
protected abstract fun getStdlibArtifactId(module: Module): String
|
||||||
|
|
||||||
fun changePomFile(
|
fun changePomFile(
|
||||||
module: Module,
|
module: Module,
|
||||||
@@ -120,7 +120,7 @@ abstract class KotlinMavenConfigurator
|
|||||||
val pom = PomFile(file as XmlFile)
|
val pom = PomFile(file as XmlFile)
|
||||||
pom.addProperty(KOTLIN_VERSION_PROPERTY, version)
|
pom.addProperty(KOTLIN_VERSION_PROPERTY, version)
|
||||||
|
|
||||||
pom.addDependency(MavenId(GROUP_ID, stdlibArtifactId, "\${$KOTLIN_VERSION_PROPERTY}"), MavenArtifactScope.COMPILE, null, false, null)
|
pom.addDependency(MavenId(GROUP_ID, getStdlibArtifactId(module), "\${$KOTLIN_VERSION_PROPERTY}"), MavenArtifactScope.COMPILE, null, false, null)
|
||||||
if (testArtifactId != null) {
|
if (testArtifactId != null) {
|
||||||
pom.addDependency(MavenId(GROUP_ID, testArtifactId, "\${$KOTLIN_VERSION_PROPERTY}"), MavenArtifactScope.TEST, null, false, null)
|
pom.addDependency(MavenId(GROUP_ID, testArtifactId, "\${$KOTLIN_VERSION_PROPERTY}"), MavenArtifactScope.TEST, null, false, null)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-stdlib</artifactId>
|
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||||
<version>${kotlin.version}</version>
|
<version>${kotlin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-stdlib</artifactId>
|
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||||
<version>${kotlin.version}</version>
|
<version>${kotlin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-stdlib</artifactId>
|
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||||
<version>${kotlin.version}</version>
|
<version>${kotlin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-stdlib</artifactId>
|
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||||
<version>${kotlin.version}</version>
|
<version>${kotlin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-stdlib</artifactId>
|
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||||
<version>${kotlin.version}</version>
|
<version>${kotlin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-stdlib</artifactId>
|
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||||
<version>${kotlin.version}</version>
|
<version>${kotlin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@
|
|||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-stdlib</artifactId>
|
<artifactId>kotlin-stdlib-jre7</artifactId>
|
||||||
<version>${kotlin.version}</version>
|
<version>${kotlin.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
Reference in New Issue
Block a user