Skip to content

Commit

Permalink
Detect and warn about the kotlinx-coroutines library in transitive …
Browse files Browse the repository at this point in the history
…dependencies
  • Loading branch information
hsz committed Sep 23, 2024
1 parent 6e96c0b commit b124656
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 26 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Added `PrepareSandboxTask.pluginName` for easier accessing of the plugin directory name
- Allow for using non-installer IDEs for plugin verification [#1715](../../issues/1715)
- Added `bundledModule()` dependency extension helpers
- Detect and warn about the `kotlinx-coroutines` library in transitive dependencies

### Changed
- Add IntelliJ Platform v2 product modules to the test classpath

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package org.jetbrains.intellij.platform.gradle.plugins.project

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.attributes.*
import org.gradle.api.attributes.java.TargetJvmVersion
import org.gradle.api.plugins.JavaPluginExtension
Expand Down Expand Up @@ -33,22 +34,8 @@ abstract class IntelliJPlatformModulePlugin : Plugin<Project> {
}

with(project.configurations) configurations@{
val intellijPlatformComposedJarConfiguration = create(Configurations.INTELLIJ_PLATFORM_COMPOSED_JAR) {
extendsFrom(
this@configurations[Configurations.External.IMPLEMENTATION],
this@configurations[Configurations.External.RUNTIME_ONLY],
)
}
val intellijPlatformDistributionConfiguration = create(Configurations.INTELLIJ_PLATFORM_DISTRIBUTION)

listOf(
intellijPlatformComposedJarConfiguration,
intellijPlatformDistributionConfiguration,
).forEach {
it.isCanBeConsumed = true
it.isCanBeResolved = false

it.attributes {
fun Configuration.applyVariantAttributes() {
attributes {
attribute(Bundling.BUNDLING_ATTRIBUTE, project.objects.named(Bundling.EXTERNAL))
attribute(Category.CATEGORY_ATTRIBUTE, project.objects.named(Category.LIBRARY))
attributeProvider(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, project.provider {
Expand All @@ -60,6 +47,30 @@ abstract class IntelliJPlatformModulePlugin : Plugin<Project> {
}
}

create(
name = Configurations.INTELLIJ_PLATFORM_COMPOSED_JAR,
description = "IntelliJ Platform final composed Jar archive",
) {
isCanBeConsumed = true
isCanBeResolved = true

applyVariantAttributes()

extendsFrom(
this@configurations[Configurations.External.IMPLEMENTATION],
this@configurations[Configurations.External.RUNTIME_ONLY],
)
}
create(
name = Configurations.INTELLIJ_PLATFORM_DISTRIBUTION,
description = "IntelliJ Platform distribution Zip archive",
) {
isCanBeConsumed = true
isCanBeResolved = false

applyVariantAttributes()
}

val intellijPlatformPluginModuleConfiguration = create(
name = Configurations.INTELLIJ_PLATFORM_PLUGIN_MODULE,
description = "IntelliJ Platform plugin module",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ abstract class VerifyPluginProjectConfigurationTask : DefaultTask(), IntelliJPla
yield("The dependency on the Kotlin Standard Library (stdlib) is automatically added when using the Gradle Kotlin plugin and may conflict with the version provided with the IntelliJ Platform, see: https://jb.gg/intellij-platform-kotlin-stdlib")
}
if (kotlinxCoroutinesLibraryPresent) {
yield("The Kotlin Coroutines library must not be added explicitly to the project as it is already provided with the IntelliJ Platform, see: https://jb.gg/intellij-platform-kotlin-coroutines")
yield("The Kotlin Coroutines library must not be added explicitly to the project nor as a transitive dependency as it is already provided with the IntelliJ Platform, see: https://jb.gg/intellij-platform-kotlin-coroutines")
}
if (runtimeMetadata.get()["java.vendor"] != "JetBrains s.r.o.") {
yield("The currently selected Java Runtime is not JetBrains Runtime (JBR). This may lead to unexpected IDE behaviors. Please use IntelliJ Platform binary release with bundled JBR or define it explicitly with project dependencies or JVM Toolchain, see: https://jb.gg/intellij-platform-with-jbr")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package org.jetbrains.intellij.platform.gradle.tasks

import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.artifacts.component.ModuleComponentIdentifier
import org.gradle.api.file.DirectoryProperty
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.provider.Property
Expand Down Expand Up @@ -232,15 +233,14 @@ internal fun <T : Task> Project.preconfigureTask(task: T) {
if (this is KotlinMetadataAware) {
kotlinPluginAvailable.convention(false)

val implementationConfiguration = project.configurations[Configurations.External.IMPLEMENTATION]
val compileOnlyConfiguration = project.configurations[Configurations.External.COMPILE_ONLY]

val composedJarConfiguration = project.configurations[Configurations.INTELLIJ_PLATFORM_COMPOSED_JAR]
kotlinxCoroutinesLibraryPresent.convention(project.provider {
listOf(implementationConfiguration, compileOnlyConfiguration).any { configuration ->
configuration.dependencies.any {
it.group == "org.jetbrains.kotlinx" && it.name.startsWith("kotlinx-coroutines")
}
}
composedJarConfiguration
.resolvedConfiguration
.resolvedArtifacts
.asSequence()
.mapNotNull { it.id.componentIdentifier as? ModuleComponentIdentifier }
.any { it.group == "org.jetbrains.kotlinx" && it.module.startsWith("kotlinx-coroutines") }
})

project.pluginManager.withPlugin(Plugins.External.KOTLIN) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class VerifyPluginProjectConfigurationTaskTest : IntelliJPluginTestBase() {
build(Tasks.VERIFY_PLUGIN_PROJECT_CONFIGURATION) {
assertContains(HEADER, output)
assertContains(
"- The Kotlin Coroutines library must not be added explicitly to the project as it is already provided with the IntelliJ Platform, see: https://jb.gg/intellij-platform-kotlin-coroutines",
"- The Kotlin Coroutines library must not be added explicitly to the project nor as a transitive dependency as it is already provided with the IntelliJ Platform, see: https://jb.gg/intellij-platform-kotlin-coroutines",
output
)
}
Expand Down

0 comments on commit b124656

Please sign in to comment.