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

How to generate code across sourcesets #799

Open
xgouchet opened this issue Jan 19, 2022 · 3 comments
Open

How to generate code across sourcesets #799

xgouchet opened this issue Jan 19, 2022 · 3 comments

Comments

@xgouchet
Copy link

xgouchet commented Jan 19, 2022

I'm trying to generate some code for my tests based on the code in my main sourceset.

If I apply my Processor to the main source sets, it sees the types I want to, but generates the output in the same sourceset, which I don't want because it's not relevant for production, and also it's missing some dependencies which are only available in test.

Is there a way to do so either in my processor implementation or in the project where I apply it? I'm using Gradle, and so far here's how it works

// build.gradle.kts
dependencies {
        add("ksp", "") // sees the source I want but generates code in either debug/release source set
        add("kspTest", "...") // generates the  code in the debugUnitTest source set, but doesn't see the main sources
}
@ting-yuan
Copy link
Collaborator

KSP follows compilation model in Gradle where main and test source sets are compiled separately. So there is no way (that I know of, without hacking Gradle too much) to process main sources together with the test sources. If you have control over the processor, maybe get symbols in main via Resolver.getClassDeclarationByName, Resolver.getDeclarationsFromPackage or through references in the test source set.

@charbgr
Copy link

charbgr commented Jun 21, 2022

Is this similar to my question here?

#962

@xgouchet
Copy link
Author

Yes it does look like we want to achieve the same thing

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

3 participants