java stab of class file generator
This is for a workaround of KT-24309.
How to use
As a Gradle Library
-
add
com.anatawa12.java-stab-gen:gradle-library:1.0.0
to buildscript depencencies.kotlin
```groovy buildscript { repositories { mavenCentral() } dependencies { classpath("com.anatawa12.java-stab-gen:gradle-library:1.0.0") } } ```groovy
```groovy buildscript { repositories { mavenCentral() } dependencies { classpath "com.anatawa12.java-stab-gen:gradle-library:1.0.0" } } ``` -
create task with type
com.anatawa12.javaStabGen.gradle.ClassesGenerator
kotlin
import com.anatawa12.javaStabGen.gradle.GenerateJavaStab val generateJavaStab by tasks.creating(GenerateJavaStab::class) { generatedDir = file("$buildDir/generated/stab") classpath = classpath_you_want_to_generate_stab_for }
groovy
import com.anatawa12.javaStabGen.gradle.GenerateJavaStab task generateJavaStab(type: GenerateJavaStab) { generatedDir = file("$buildDir/generated/stab") classpath = classpath_you_want_to_generate_stab_for }
Examples
Workaround of KT-24309
groovy
import com.anatawa12.javaStabGen.gradle.GenerateJavaStab
def theLibraryDependsThisProject = TODO
// generate stab for $theLibraryDependsThisProject
// into "$buildDir/generated/stab"
task generateJavaStab(type: GenerateJavaStab) {
generatedDir = file("$buildDir/generated/stab")
classpath = files(theLibraryDependsThisProject)
}
compileKotlin {
dependsOn(generateJavaStab)
// add and include generateJavaStab.generatedDir as java source code
source(generateJavaStab.generatedDir)
include("**/*.java")
}