Hi <@U0234N0QYSK>, I was wondering if we need a sp...
# compose-destinations
i
Hi @Rafael Costa, I was wondering if we need a special setup to create reusable destination annotations in other modules (multi-module project)? Following the documentation I created a setup to create a reusable destination that adds a wrapper. I got it working when everything is defined in 1 module. However, if the reusable destination is in another module, the destinations annotated with that one cannot be generated anymore.
Current setup: Shared module:
Copy code
@Repeatable
@Destination<Nothing>(
    wrappers = [MyWrapper::class]
)
annotation class AuthenticatedDestination<T: Annotation>
Feature X module:
Copy code
@NavGraph<ExternalModuleGraph>
internal annotation class FeatureXNavGraph

@AuthenticatedDestination<FeatureXNavGraph>
internal annotation class FeatureXDestination(
    val start: Boolean = false
)

@FeatureXDestination(
    start = true
)
@Composable
internal fun FeatureXScreen() { ... }
r
You mean that the AuthenticatedDestination annotation is in another module different than FeatureXDestination?
Can you tell me what exactly do you see? Are classes not generated (which ones) or there’s an error?
i
Yes, AuthenticatedDestination is in another module, which I would like all features to have access to, such as Feature X. I put the wrapper and the AuthenticatedDestination in the shared module, ran
./gradlew kspDebugKotlin
and got a compile error because of unresolved references in my imports as the generated destinations are cleaned and not generated again.
Copy code
> Task :x:compileDebugKotlin FAILED
e: file:///Users/dev/AndroidStudioProjects/.../src/main/kotlin/.../FeatureXOverviewScreen.kt:36:71 Unresolved reference 'FeatureXDetailScreenDestination'.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':featurex:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details
Compared to my other modules, only the
_ModuleRegistry_FeatureX
file is generated. No generated destinations under
com.ramcosta.composedestinations.generated.featurex
, which were generated when the AuthenticatedDestination and wrapper were defined in the FeatureX module instead of another module.
r
Yeah I don’t think there’s a way to make this work right now 🤔 When processing a given module, we start by checking usages of @Destination. But in this case that usage is in different module.
What happens if you annotate the FeatureXDestination also with @Destination?
i
That will compile. However a second @destination, which has an empty wrappers parameter, will override the wrappers of AuthenticatedDestination and not trigger the wrapper anymore.
r
So the AuthenticatedDestination is ignored basically?
i
I think so yes. It only sets the wrappers and a second annotation always overrides the same parameters when a value is provided such as an empty []
I would need to add the wrapper directly on the FeatureXDestination annotation, which defeats the purpose of the use of a common AuthenticatedDestination
r
Just to confirm, have you tried it?
i
Yes
r
Ok.. as a workaround, if each module uses the wrapper directly, even if that wrapper is in a shard module, that works right?
For example you’d put the wrapper in the FeatureXDestination instead of using @AuthenticatesDestination.
i
Yes, since the wrapper is just an object. 👍
r
Ok, that doesn’t seem too bad for a workaround right? It’s an extra line per module
i
Tried with @ExternalDestination in the graph, just for the sake of it, and that doesn't do the trick either 😉 But yeah I can live with an extra line per feature. All together v2 is still a great improvement over v1 🙌
r
Glad you like it 🙂