Skip to content

Commit

Permalink
Make compose compiler version configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
jeppeman committed Mar 26, 2024
1 parent 43906de commit c3cc6cf
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 20 deletions.
26 changes: 12 additions & 14 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
[versions]
kotlin = '1.9.22'
compose-ui = '1.5.4'
compose-compiler = '1.5.8'
google-ksp = '1.9.22-1.0.16'
kotlin = '1.9.23'
compose-ui = '1.6.4'
compose-compiler = '1.5.11'
google-ksp = '1.9.23-1.0.19'
activity = '1.8.2'
agp = '8.2.1'
espresso = '3.4.0'
hamcrest = '2.2'
agp = '8.2.2'
espresso = '3.5.1'
mockk = '1.13.2'
mockito = '4.8.1'

[libraries]
kotlin-stdlib = { module = 'org.jetbrains.kotlin:kotlin-stdlib-jdk7', version.ref = 'kotlin' }
kotlin-gradle = { module = 'org.jetbrains.kotlin:kotlin-gradle-plugin', version.ref = 'kotlin' }
kotlin-compiler = { module = 'org.jetbrains.kotlin:kotlin-compiler-embeddable', version.ref = 'kotlin' }

androidx-activity = { module = 'androidx.activity:activity', version.ref = 'activity' }
androidx-appcompat = { module = 'androidx.appcompat:appcompat', version = '1.5.1' }
androidx-appcompat = { module = 'androidx.appcompat:appcompat', version = '1.6.1' }
androidx-activity-compose = { module = 'androidx.activity:activity-compose', version.ref = 'activity' }
androidx-lifecycle-viewmodel-compose = { module = 'androidx.lifecycle:lifecycle-viewmodel-compose', version = '2.5.1' }
androidx-test-runner = { module = 'androidx.test:runner', version = '1.2.0'}
androidx-lifecycle-viewmodel-compose = { module = 'androidx.lifecycle:lifecycle-viewmodel-compose', version = '2.7.0' }
androidx-test-runner = { module = 'androidx.test:runner', version = '1.5.2'}
androidx-test-espresso-core = { module = 'androidx.test.espresso:espresso-core', version.ref = 'espresso' }
androidx-fragment-testing = { module = 'androidx.fragment:fragment-testing', version = '1.5.4' }
androidx-fragment-testing = { module = 'androidx.fragment:fragment-testing', version = '1.6.2' }

compose-compiler = { module = 'androidx.compose.compiler:compiler', version.ref = 'compose-compiler' }
compose-runtime = { module = 'org.jetbrains.compose.runtime:runtime', version = '1.4.1' }
compose-ui = { module = 'androidx.compose.ui:ui', version.ref = 'compose-ui' }
compose-material = { module = 'androidx.compose.material:material', version = '1.4.0' }
compose-foundation = { module = 'androidx.compose.foundation:foundation', version = '1.4.0' }
compose-material = { module = 'androidx.compose.material:material', version = '1.6.4' }
compose-foundation = { module = 'androidx.compose.foundation:foundation', version = '1.6.4' }
compose-ui-test-junit4 = { module = 'androidx.compose.ui:ui-test-junit4', version.ref = 'compose-ui' }
compose-ui-test-manifest = { module = 'androidx.compose.ui:ui-test-manifest', version.ref = 'compose-ui' }

Expand Down
1 change: 1 addition & 0 deletions integration-tests/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {

mockposable {
plugins = listOf(MOCKK, MOCKITO, COMPOSE_UI)
composeCompilerPluginVersion = libs.versions.compose.compiler.get()
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fun compile(
val mockposableCommandLineProcessor = MockposableCommandLineProcessor()
val composeCommandLineProcessor = ComposeCommandLineProcessor()
return KotlinCompilation().apply {
languageVersion = "1.8"
languageVersion = "1.9"
sources = sourceFiles
commandLineProcessors = listOf(mockposableCommandLineProcessor, composeCommandLineProcessor)
componentRegistrars = listOf(ComposePluginRegistrar(), MockposablePlugin())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,16 @@ class MockposableSubPlugin : KotlinCompilerPluginSupportPlugin {
.dependencies
.add(project.dependencies.create(COMPOSE_RUNTIME_COORDINATES))

val composeCompilerDependency = if (extension.composeCompilerPluginVersion.isNotBlank()) {
project.dependencies.create(COMPOSE_COMPILER_COORDINATES.dropLastWhile { it != ':' } + extension.composeCompilerPluginVersion)
} else {
project.dependencies.create(COMPOSE_COMPILER_COORDINATES)
}

project.configurations
.getByName(PLUGIN_CLASSPATH_CONFIGURATION_NAME)
.dependencies
.add(project.dependencies.create(COMPOSE_COMPILER_COORDINATES))
.add(composeCompilerDependency)

return project.provider {
listOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.jeppeman.mockposable.gradle

abstract class MockposableSubPluginExtension {
var composeCompilerPluginVersion: String = ""
var plugins: List<String> = emptyList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ object Mockposable {
/**
* Runs the initial composition of a composable function and returns its result.
*/

@Suppress("UNCHECKED_CAST")
fun <T> runComposableOneShot(useActiveComposer: Boolean = false, block: @Composable () -> T): T {
if (!useActiveComposer || Mockposable.activeComposer == null) {
Expand All @@ -24,10 +23,10 @@ fun <T> runComposableOneShot(useActiveComposer: Boolean = false, block: @Composa
val composition = Composition(UnitApplier, recomposer)
composition.setContent {
result = block()
composition.dispose()
SideEffect { composition.dispose() }
recomposer.close()
/* We're just looking to execute block() and escape as soon as possible. Perhaps
there is a more elegant way of doing this, but this gets the job done. */
// We're just looking to execute block() and escape as soon as possible. Perhaps
// there is a more elegant way of doing this, but this gets the job done.
cancel()
}
}
Expand Down

0 comments on commit c3cc6cf

Please sign in to comment.