Browse Source
* Add a warning for a user who sets `compose.kotlinCompilerPlugin` to `android.compose.compiler.compiler` The warning will show up only when a multiplatform project contains at least one of the non-jvm targets: k/js, k/native or k/wasm * fix typo * PR review * Refactor to BuildService * fix typopull/3325/head
Oleksandr Karpovich
1 year ago
committed by
GitHub
4 changed files with 156 additions and 1 deletions
@ -0,0 +1,62 @@
|
||||
package org.jetbrains.compose |
||||
|
||||
import org.gradle.api.Project |
||||
import org.gradle.api.logging.Logging |
||||
import org.gradle.api.provider.Provider |
||||
import org.gradle.api.provider.SetProperty |
||||
import org.gradle.api.services.BuildService |
||||
import org.gradle.api.services.BuildServiceParameters |
||||
import org.gradle.api.services.BuildServiceRegistry |
||||
import org.gradle.tooling.events.FinishEvent |
||||
import org.gradle.tooling.events.OperationCompletionListener |
||||
import org.jetbrains.kotlin.gradle.plugin.SubpluginArtifact |
||||
|
||||
// The service implements OperationCompletionListener just so Gradle would use the service |
||||
// even if the service is not used by any task or transformation |
||||
abstract class ComposeMultiplatformBuildService : BuildService<ComposeMultiplatformBuildService.Parameters>, |
||||
OperationCompletionListener, AutoCloseable { |
||||
interface Parameters : BuildServiceParameters { |
||||
val unsupportedCompilerPlugins: SetProperty<Provider<SubpluginArtifact?>> |
||||
} |
||||
|
||||
private val log = Logging.getLogger(this.javaClass) |
||||
|
||||
override fun close() { |
||||
notifyAboutUnsupportedCompilerPlugin() |
||||
} |
||||
|
||||
private fun notifyAboutUnsupportedCompilerPlugin() { |
||||
val unsupportedCompilerPlugin = parameters.unsupportedCompilerPlugins.orNull |
||||
?.firstOrNull() |
||||
?.orNull |
||||
|
||||
if (unsupportedCompilerPlugin != null) { |
||||
log.error(createWarningAboutNonCompatibleCompiler(unsupportedCompilerPlugin.groupId)) |
||||
} |
||||
} |
||||
|
||||
override fun onFinish(event: FinishEvent) {} |
||||
|
||||
companion object { |
||||
fun configure(project: Project, fn: Parameters.() -> Unit): Provider<ComposeMultiplatformBuildService> = |
||||
project.gradle.sharedServices.registerOrConfigure<Parameters, ComposeMultiplatformBuildService> { |
||||
fn() |
||||
} |
||||
|
||||
fun provider(project: Project): Provider<ComposeMultiplatformBuildService> = configure(project) {} |
||||
} |
||||
} |
||||
|
||||
inline fun <reified P : BuildServiceParameters, reified S : BuildService<P>> BuildServiceRegistry.registerOrConfigure( |
||||
crossinline fn: P.() -> Unit |
||||
): Provider<S> { |
||||
val serviceClass = S::class.java |
||||
val serviceFqName = serviceClass.canonicalName |
||||
val existingService = registrations.findByName(serviceFqName) |
||||
?.apply { (parameters as? P)?.fn() } |
||||
?.service |
||||
return (existingService as? Provider<S>) |
||||
?: registerIfAbsent(serviceFqName, serviceClass) { |
||||
it.parameters.fn() |
||||
} |
||||
} |
@ -0,0 +1,44 @@
|
||||
package org.jetbrains.compose.test.tests.integration |
||||
|
||||
import org.jetbrains.compose.createWarningAboutNonCompatibleCompiler |
||||
import org.jetbrains.compose.test.utils.GradlePluginTestBase |
||||
import org.jetbrains.compose.test.utils.TestProjects |
||||
import org.jetbrains.compose.test.utils.checks |
||||
import org.junit.jupiter.api.Test |
||||
|
||||
class UnsupportedCompilerPluginWarningTest : GradlePluginTestBase() { |
||||
|
||||
private val androidxComposeCompilerGroupId = "androidx.compose.compiler" |
||||
private val androidxComposeCompilerPlugin = "$androidxComposeCompilerGroupId:compiler:1.4.8" |
||||
|
||||
@Suppress("RedundantUnitExpression") |
||||
@Test |
||||
fun testKotlinJs_shows_warning_for_androidx_compose_compiler() = testProject( |
||||
TestProjects.customCompilerArgs, defaultTestEnvironment.copy( |
||||
kotlinVersion = "1.8.22", |
||||
composeCompilerPlugin = "\"$androidxComposeCompilerPlugin\"", |
||||
composeCompilerArgs = "\"suppressKotlinVersionCompatibilityCheck=1.8.22\"" |
||||
) |
||||
).let { |
||||
it.gradle(":compileKotlinJs").checks { |
||||
check.taskSuccessful(":compileKotlinJs") |
||||
check.logContains(createWarningAboutNonCompatibleCompiler(androidxComposeCompilerGroupId)) |
||||
} |
||||
Unit |
||||
} |
||||
|
||||
@Suppress("RedundantUnitExpression") |
||||
@Test |
||||
fun testKotlinJvm_doesnt_show_warning_for_androidx_compose_compiler() = testProject( |
||||
TestProjects.customCompiler, defaultTestEnvironment.copy( |
||||
kotlinVersion = "1.8.22", |
||||
composeCompilerPlugin = "\"$androidxComposeCompilerPlugin\"", |
||||
) |
||||
).let { |
||||
it.gradle(":run").checks { |
||||
check.taskSuccessful(":run") |
||||
check.logDoesntContain(createWarningAboutNonCompatibleCompiler(androidxComposeCompilerGroupId)) |
||||
} |
||||
Unit |
||||
} |
||||
} |
Loading…
Reference in new issue