Comments (4)
We had the same problem on our project. We basically "solved" it by making a fake target through gradle at build time which has the same configuration like the actual target we want to build. During the compilation of the fake target, the generated code is created and added to the source set and thus available when the actual target is built.
An ugly hack but with the current way compiler plugins are made, it seems not to be possible to achieve this like with the kapt annotation processors for the jvm. The only other solution would be to directly generate IR for the kotlin compiler like the kotlinx Serialization plugin does. But then you end up with code that is not debuggable.
So a trade of either way.
Edit: from here on we create the dummy target: https://github.com/utopia-rise/godot-kotlin/blob/521476cececfa13cbc86cb3b9e7d9eb3a3bd15be/plugins/godot-gradle-plugin/src/main/kotlin/godot/gradle/GodotPlugin.kt#L73 if you want to have a look on how to setup this
from mpapt.
Looks cool! But doesn't work on my side :(
The reason is: you made a virtual target with custom source set name (godot[Main|Test]).
But I have a jvm default source set.
Well, it still could be achieved with your's way. But I need to change whole project's structure :(
I'm digging deeper to kotlinx.serialization... What do you mean saying "directly generate IR"?
from mpapt.
Yes depending on the size of the project that's not feasible at all.
You can directly generate the Intermediate Representation (IR) of the code you want to generate. This is the format the kotlin compiler uses to generate the ByteCode for the various platforms.
But as of now this is very poorly documented and not a stable API yet. With Kotlin 1.4 it seems they want to improve that situation.
That said I'm by no means an expert on how to generate IR. On our project we'll start into looking to directly generate IR with kotlin 1.4 soon so not much experiance on my side. Your best bet seems to be the kotlinx.Serialization plugin.
Also a good starting point might be this set of slides: https://resources.jetbrains.com/storage/products/kotlinconf2018/slides/5_Writing%20Your%20First%20Kotlin%20Compiler%20Plugin.pdf
from this talk: https://www.youtube.com/watch?v=w-GMlaziIyo
Although he directly generates JVM bytecode from it, it might get you more familiar with what to look for.
But maybe @Foso has a better idea on how to tackle this problem which is quite similar with what i eluded here: #11
There i also linked another possible but really hacky "solution" by generating the code in advance of the compilation process by parsing kotlin code yourself with the help of the kotlin compiler frontend.
Shortcut if you don't want to read the issue: https://github.com/vektory79/kotlin-script-parser-test/blob/master/src/main/java/hello/CompileTest.kt
from mpapt.
Hi, sorry for the late answer, unfortunately i don't have a better solution yet, but i will take a look if Kotlin 1.4.0 offers some new opportunities
from mpapt.
Related Issues (14)
- [Question/Help Wanted] Annotation Processor get's called to late in the process? HOT 8
- [Question/Help wanted] Resolving dependencies between the different Gradle modules HOT 2
- ComponentRegistrar is not being called HOT 5
- Expression annotations are only detected on function declarations- HOT 1
- Help wanted HOT 2
- Help Wanted: Only one Expression Annotation is detected HOT 1
- KotlinGradleSubplugin is deprecated in 1.4.0 HOT 2
- GradlePlugin -> KotlinCompilerPlugin fails HOT 1
- I will the change the checking for supported target platforms
- Compilation faillure on classes without properties HOT 1
- Just discovered the DeclarationChecker Class
- Support warning/error messages HOT 3
- Problem guessing build folder when deploying to Heroku HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mpapt.