I am trying to get joint/mixed compilation between all of Java, Groovy and Kotlin. I am currently working on a theory that it should be possible if groovyc can be made to just emit stub-files as a first stage.
Can it? Otherwise, any pointers towards making such a feature out of the sources of Groovy?
Here's the idea of full mixed compilation:
Groovy is a compiled language, but it allows you to execute scripts. Calling groovy like you did compiles and runs the script.
The Groovy compiler seems to compile directly from source to bytecode: groovyc is the Groovy compiler command line tool. It allows you to compile Groovy sources into bytecode. It plays the same role as javac in the Java world.
For most Groovy scripts I use, I simply run the script from its Groovy source code as-is and allow the compilation to take place implicitly. However, it can be helpful at times to use groovyc to compile Groovy code into . class files and then execute those . class files via the normal Java launcher (java).
This is relatively easy to do programmatically but not something currently supported from the command line. For programmatic usage, you'd need something like [1], but with the phase on the referenced line changed to SEMANTIC_ANALYSIS. You'd also need to keep the stubs as per [2].
To enable this from the command line, the FileSystemCompiler would need to know about a finishing phase and the unit.compile() statements at [3] would need to be made aware of that phase. But I haven't actually tried those changes myself.
[1] https://github.com/apache/groovy/blob/master/src/test/groovy/bugs/Groovy6086Bug.groovy#L63
[2] https://github.com/apache/groovy/blob/master/src/test/groovy/bugs/Groovy9031.groovy#L33
[3] https://github.com/apache/groovy/blob/master/src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java#L309-L317
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With