Skip to content

1.3.0

Latest

Choose a tag to compare

@ZacSweers ZacSweers released this 01 Jul 05:18

New

  • [IR] Revamp graph-validation diagnostics with structured output. Taking some inspiration from Rust error messages.

    • Stable diagnostic IDs

    • Compact dependency chains

    • Aligned binding traces

    • Source snippets

    • help:/note: guidance in messages (replaces the previous (hint) sections)

    • Per-diagnostic docs links

    • Diagnostics now wrap to 100 columns and start on their own line after the compiler location prefix

    • Example plain output

      ExampleGraph.kt:9:3: error: 
      [Metro/MissingBinding] No binding found for String
      
        trace (in dev.zacsweers.example.ExampleGraph):
            String is requested at dev.zacsweers.example.ExampleGraph.a
      
        similar bindings:
            - CharSequence (Supertype. Type: Provided) - ExampleGraph.kt:12:3
      
        help: ensure String has an @Inject constructor or is provided by an @Provides or @Binds
              declaration visible to ExampleGraph
        docs: https://zacsweers.github.io/metro/latest/diagnostics/#missingbinding
      
    • Example rich output

      (note that in rich terminals this would have color and markup too!)

      ExampleGraph.kt:9:3: error: 
        ╭─ [Metro/MissingBinding] No binding found for String
        │ → ExampleGraph.kt:9:3
        │
      9 │   val a: String
        │   ⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃⌃
        ╰─
      
        trace (in dev.zacsweers.example.ExampleGraph):
            String is requested at dev.zacsweers.example.ExampleGraph.a
      
        similar bindings:
            • CharSequence (Supertype. Type: Provided) — ExampleGraph.kt:12:3
      
        help: ensure String has an @Inject constructor or is provided by an @Provides or @Binds
              declaration visible to ExampleGraph
        docs: https://zacsweers.github.io/metro/latest/diagnostics/#missingbinding
      
  • [runtime/JVM] Add experimental runtime tracing for generated graph code, backed by AndroidX Tracing 2.x. Enable it with metro.enableRuntimeTracing. See the runtime tracing performance docs for setup guidance.

    • Metro will add the JVM-only metro-trace runtime helper artifact.
    • Graphs must bind an androidx.tracing.Tracer instances as a graph input as a parent tracer.
    • This is experimental as AndroidX Tracing 2.x is still actively being developed.
  • [gradle] Add a diagnosticsRenderMode Gradle option (AUTO/PLAIN/RICH) for diagnostic rendering.

    • AUTO defaults to rich output and falls back to plain output for non-empty NO_COLOR, --console=plain, and IDE-invoked builds.
    • The resolved mode is passed as a non-input compiler option, so render-mode changes do not invalidate compilation or poison build caches.
  • [docs] Add a generated Diagnostics Reference docs page for Metro's common graph validation diagnostics.

  • [FIR/IR] Add support for parameterless @Binds declarations for constructor-injected classes.

Enhancements

  • [FIR] Add a diagnostic to report mutable graph accessor properties.
  • [FIR] Add a diagnostic to report open classes annotated with @BindingContainer.
  • [FIR] Add a diagnostic to report scope annotations on graph factory parameters.
  • [IR] Add cycle-breaking help: guidance for dependency cycle errors, suggesting deferred types such as () -> T or Lazy<T>.
  • [IR/reporting] Collapse sibling missing-binding errors with identical trace tails to a ... same as for X continuation, and fully qualify type names only when two distinct types in one diagnostic share a simple name.
  • [docs] Improve docs around @GraphPrivate.

Fixes

  • [FIR] Improve diagnostic reporting locations for assisted factory parameter mismatches.
  • [FIR/IR] Fully qualify generated hint function names so scope classes with the same simple name don't collide.
  • [IR] Preserve substituted generic type arguments when generating assisted factory delegate parameters and dynamic graph container inputs.
  • [IR] Forward extension and context receivers when generated binding-container factories invoke the original binding function.
  • [IR] Fix dispatch receivers for generated graph factory functions and companion/object factory accessors.
  • [IR] Manage transitive simple class binding containers included by contributed binding containers when they have instance providers.
  • [IR] Patch declaration parents for generated @Binds mirror declarations so copied declarations remain attached to the correct generated class.
  • [IR] Preserve @GraphPrivate on cross-module mirror functions so private multibinding contributions do not leak through chained graph extensions.
  • [IR/Dagger interop] Report a clear diagnostic when an injected declaration or binding container from an upstream module was not processed by Metro, instead of crashing or reporting a generic compiler error.
  • [IR/Dagger interop] Fix an IR gen crash when an unscoped parent @Provides binding is injected as dagger.Lazy<T> from a child graph.
  • [IR/JS] Fix Map<K, () -> V> multibindings accessed through provider-style map factories on Kotlin/JS. Generated maps now store callable function values instead of Metro Provider objects.
  • [IR/KLIB] Fix generated @Binds implementations on KLIB backends. Metro now emits concrete identity bodies for inherited @Binds members where JS, Native, and Wasm validate abstract members during deserialization.
  • [IR/KLIB] Keep generated graph and shard backing fields private while preserving generated access through properties. This avoids backing-field visibility validation failures on KLIB backends.
  • [gradle] Fix multiplatform output collisions in MetroArtifactCopyTask.

Changes

  • Run Metro's functional compiler unit tests on JS.
  • Redundant checksum files are no longer published: checksums of .asc signature files (gradle/gradle#20232) and the sha256/sha512. If you rely on these, let me know.
  • Remove binding-contributions-as-containers flag, only binding-contributions-as-containers is supported going forward.
  • [gradle] Build against Gradle 9.6.1.
  • Test Kotlin 2.4.10-RC.
  • Test Kotlin 2.4.20-Beta1.
  • Test Android Studio Quail 2 RCs.
  • Test Android Studio Quail 3 canaries.

Contributors

Special thanks to the following contributors for contributing to this release!

Consider sponsoring Metro's development

What's Changed

New Contributors

Full Changelog: 1.2.1...1.3.0