Skip to content

Commit

Permalink
Detect and warn if project adds an explicit dependency on Kotlin Coro…
Browse files Browse the repository at this point in the history
…utines library
  • Loading branch information
hsz committed Sep 6, 2023
1 parent a759cec commit 851ad7a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Configure all tasks that extend task classes instead of just those created by the plugin
- Make JbrResolver prefer Gradle javaToolchains by `JetBrains s.r.o`, if available. Only otherwise start fetching and running a new one.
- Support for Kotlin Coroutines debugging
- Detect and warn if project adds an explicit dependency on Kotlin Coroutines library

### Changed
- Disabled caching for `BuildPluginTask`
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/org/jetbrains/intellij/IntelliJPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,13 @@ abstract class IntelliJPlugin : Plugin<Project> {
it.targetCompatibility
})
pluginVerifierDownloadDir.convention(downloadDirProvider)
kotlinxCoroutinesLibraryPresent.convention(project.provider {
listOf(IMPLEMENTATION_CONFIGURATION_NAME, COMPILE_ONLY_CONFIGURATION_NAME).any { configurationName ->
project.configurations.getByName(configurationName).dependencies.any {
it.group == "org.jetbrains.kotlinx" && it.name.startsWith("kotlinx-coroutines")
}
}
})

kotlinPluginAvailable.convention(project.provider {
project.pluginManager.hasPlugin(KOTLIN_GRADLE_PLUGIN_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ abstract class VerifyPluginConfigurationTask @Inject constructor(
@get:Internal
abstract val pluginVerifierDownloadDir: Property<String>

/**
* This variable represents whether the Kotlin Coroutines library is added explicitly to the project dependencies.
*/
@get:Internal
abstract val kotlinxCoroutinesLibraryPresent: Property<Boolean>

private val context = logCategory()

init {
Expand Down Expand Up @@ -190,6 +196,9 @@ abstract class VerifyPluginConfigurationTask @Inject constructor(
if (kotlinPluginAvailable.get() && kotlinVersion >= Version(1, 8, 20) && kotlinVersion < Version(1, 9) && kotlinIncrementalUseClasspathSnapshot.orNull == null) {
yield("The Kotlin plugin in version $kotlinVersion used with the Gradle IntelliJ Plugin leads to the 'java.lang.OutOfMemoryError: Java heap space' exception, see: https://jb.gg/intellij-platform-kotlin-oom")
}
if (kotlinxCoroutinesLibraryPresent.get()) {
yield("The Kotlin Coroutines library should not be added explicitly to the project as it is already provided with the IntelliJ Platform.")
}
}.joinToString("\n") { "- $it" }.takeIf(String::isNotEmpty)?.let {
warn(
context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,25 @@ class VerifyPluginConfigurationTaskSpec : IntelliJPluginSpecBase() {
}
}

@Test
fun `report kotlinx-coroutines dependency`() {
buildFile.groovy(
"""
dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.7.1")
}
""".trimIndent()
)

build(VERIFY_PLUGIN_CONFIGURATION_TASK_NAME).let {
assertContains(HEADER, it.output)
assertContains(
"- The Kotlin Coroutines library should not be added explicitly to the project as it is already provided with the IntelliJ Platform.",
it.output
)
}
}

companion object {
const val HEADER = "The following plugin configuration issues were found"
}
Expand Down

0 comments on commit 851ad7a

Please sign in to comment.