Deprecated Modules

June 12, 2026 ยท View on GitHub

composable_preview_scanner_overview_deprecated.png

Warning

The :common and :jvm modules are deprecated and will be removed in version 0.10.0. Starting with Compose Multiplatform 1.10.0-beta02, Common and Desktop @Preview annotations are deprecated in favour of the Android @Preview annotation (androidx.compose.ui.tooling.preview.Preview), which can be used across common and desktop platforms as well. After migrating to these Android @Previews, please migrate to using AndroidComposablePreviewScanner as described in the main README.md.

Common Previews (Deprecated)

You can find executable examples here:

And also a video on how to set it with Roborazzi here, and the repo used in the video here.

Executable examples with Instrumentation-based screenshot testing libraries are coming soon.

Since Compose Multiplatform 1.6.0, JetBrains has added support for @Previews in common. ComposablePreviewScanner can also scan such Previews when running on any jvm-target, like

  • Android
  • Desktop
  • Jvm

ComposablePreviewScanner provides a CommonComposablePreviewScanner for that purpose.

Assuming that you have:

  • some Compose Multiplatform @Previews defined in common
  • some jvm-target module (i.e. Android or Desktop) where you want to run screenshot tests for those @Previews. That's because ComposablePreviewScanner only works in jvm-targets for now.

Here is how you could also run screenshot tests for those Compose Multiplatform @Previews together, for instance, with Roborazzi (would also work with Paparazzi or any Instrumentation-based library).

  1. Add :common dependency for ComposablePreviewScanner:
// Maven Central
testImplementation("io.github.sergio-sastre.ComposablePreviewScanner:common:<version>")

// JitPack
testImplementation("com.github.sergio-sastre.ComposablePreviewScanner:common:<version>")
  1. Add an additional Parameterized screenshot test for these Compose Multiplatform @Previews. This is basically the same as in the corresponding Paparazzi, Roborazzi, or Instrumentation screenshot tests sections, but use CommonComposablePreviewScanner<CommonPreviewInfo> and CommonPreviewScreenshotIdBuilder.
  2. Run these screenshot tests by executing the corresponding command e.g. for android: ./gradlew yourModule:recordRoborazziDebug

Desktop Previews (Deprecated)

You can find a video on how to set it with Roborazzi here, and the repo used in the video here.

Compose-Desktop previews have AnnotationRetention.SOURCE and therefore it is not visible to ClassGraph. However, it is also possible to workaround this limitation with ComposablePreviewScanner as follows.

  1. Add :jvm dependency from ComposablePreviewScanner 0.2.0+ and use Roborazzi:
// Maven Central
testImplementation("io.github.sergio-sastre.ComposablePreviewScanner:jvm:<version>")

// JitPack
testImplementation("com.github.sergio-sastre.ComposablePreviewScanner:jvm:<version>")
  1. Configure Roborazzi as described in the corresponding "Multiplatform support" section

  2. Define your own annotation. The only condition is not to define AnnotationRetention.SOURCE

    package my.package.path
       
    @Target(AnnotationTarget.FUNCTION)
    annotation class DesktopScreenshot
    
  3. Annotate the Desktop Composables you want to generate screenshot tests for with this annotation, e.g.

    @DesktopScreenshot
    @Preview // It'd also work without this annotation
    @Composable
    fun MyDesktopComposable() { 
        // Composable code here
    }
  1. Create the parameter provider for the Parameterized test. We can use TestParameterInjector for that
class DesktopPreviewProvider : TestParameterValuesProvider() {
  @OptIn(RequiresShowStandardStreams::class)
  override fun provideValues(context: Context?): List<ComposablePreview<JvmAnnotationInfo>> =
    JvmAnnotationScanner("my.package.path.DesktopScreenshot")
      .enableScanningLogs()
      .scanPackageTrees("previews")
      .getPreviews()
}
  1. Write the Parameterized test itself
fun screenshotNameFor(preview: ComposablePreview<JvmAnnotationInfo>): String =
   "$DEFAULT_ROBORAZZI_OUTPUT_DIR_PATH/${preview.declaringClass}.${preview.methodName}.png"

@RunWith(TestParameterInjector::class)
class DesktopPreviewTest(
   @TestParameter(valuesProvider = DesktopPreviewProvider::class)
   val preview: ComposablePreview<JvmAnnotationInfo>
) {
   @OptIn(ExperimentalTestApi::class)
   @Test
   fun test() {
      ROBORAZZI_DEBUG = true
      runDesktopComposeUiTest {
         setContent { preview() }
         onRoot().captureRoboImage(
            filePath = screenshotNameFor(preview),
         )
      }
   }
}
  1. Run these Roborazzi tests by executing the corresponding command e.g. ./gradlew yourModule:recordRoborazziJvm (if using the Kotlin Jvm Plugin)