comahe-de / i18n4k

Internationalization for Kotlin
Apache License 2.0
77 stars 9 forks source link

i18n4k is causing issues when used with projects that use KSP / eager evaluation methods should be replaced with lazy evaluation methods #33

Closed bitspittle closed 11 months ago

bitspittle commented 11 months ago

I'm the author of a project called Kobweb, which uses KSP. One of my users reported a callstack that came from this plugin.

image

with this error:

* What went wrong:
A problem occurred configuring project ':site'.
> Could not create task ':site:kobwebExport'.
   > Task with name 'kspKotlinJs' not found in project ':site'.

They said they saw a similar error when using ktorfit with your plugin, and that is another project that uses ksp.

After some investigation, we think this line is the culprit, forcing eager evaluation before other plugins are ready :

https://github.com/comahe-de/i18n4k/blob/c8516196097279dd58411c2b7b34c703dfddb1a6/i18n4k-gradle-plugin/src/main/kotlin/de/comahe/i18n4k/gradle/plugin/I18n4kPlugin.kt#L121C20-L121C20

It should probably be rewritten as

project.tasks.matching { it.name.startsWith("compile") }.configureEach {
   it.dependsOn(GENERATE_I18N_SOURCES_TASK_NAME)
}

You should probably also change the withType.forEach calls to withType.configureEach and the findByName calls also to use matching.

I'm not a Gradle expert, nor am I sure if you fix this it will fix the issues I'm seeing with the error linked above, but making these changes are, to my understanding, modern Gradle best practices. See also: https://docs.gradle.org/current/userguide/task_configuration_avoidance.html

bitspittle commented 11 months ago

If you want to repro this for yourself....

comahe-de commented 11 months ago

@ bitspittle Thank you for your bug report. I could reproduce it and your suggested change fixed the issue.

Version 0.6.2 is in the pipeline...