Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ksp] Add support for reading generated resource files #70

Open
ansman opened this issue Sep 28, 2020 · 4 comments
Open

[ksp] Add support for reading generated resource files #70

ansman opened this issue Sep 28, 2020 · 4 comments

Comments

@ansman
Copy link
Contributor

ansman commented Sep 28, 2020

Currently the only way to read resource files generated by a KSP symbol processor is to use File(KotlinCompilation.kspSourcesDir, "resource") which is only available from KotlinCompilation and not KotlinCompilation.Result. It would be nice if there was a more standardized way to read generated resource files when using KSP.

@tschuchortdev
Copy link
Owner

Can you give some examples how you generate and access resource files from within KAPT or KSP in a regular Gradle project? Currently I don't have time to really investigate but I've done some superficial research and it seems that resource files are not managed by javac/kotlinc, so anything you do with resource files only works "accidentally" and is specific to the build system. If it works in a Java project then it doesn't necessarily also work the same way in an Android project and some things like incremental compilation or multiple rounds processing might not work at all for resource files. Still it's probably useful to replicate the Gradle behaviour if possible.

@ansman
Copy link
Contributor Author

ansman commented Sep 29, 2020

I'm generating the required metadata resource files for Gradle plugins. You can see how the file is generated here: https://github.com/ansman/auto-plugin/pull/2/files#diff-076fd4f8b560d131d682cc12aaf63c54R95

The goal is just to include it in the final jar when packaging.

@ZacSweers
Copy link
Contributor

@gfreivasc
Copy link

I'm currently using a workaround to have access to generated sources, and mentioned it in #129. A slightly modified version could work for resources as well.

internal val KotlinCompilation.Result.workingDir: File get() =
  outputDirectory.parentFile!!

val KotlinCompilation.Result.kspGeneratedReources: List<File> get() {
  val kspWorkingDir = workingDir.resolve("ksp")
  val kspGeneratedResources = kspWorkingDir.resolve("sources")
    .resolve("resources")
  return kspGeneratedResources.listFilesRecursively()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants