From 4775756fb0eb352a8ac6cbdc47e711b56d3f7b2d Mon Sep 17 00:00:00 2001 From: Clinton Alexander Date: Thu, 16 Mar 2017 14:04:55 +0000 Subject: [PATCH] Entirely separated the generation step from the jar step allowing for separate running of kapt and packaging. --- node-schemas/build.gradle | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/node-schemas/build.gradle b/node-schemas/build.gradle index 21ec7ae360..56e61cfd6c 100644 --- a/node-schemas/build.gradle +++ b/node-schemas/build.gradle @@ -16,8 +16,15 @@ repositories { } } +// Kapt plugin is hardcoded in output directory and sourcesets. Use a separate sourceset to keep the generated +// files in git and outside of the build directory (to avoid cleaning issues) sourceSets { main { + kotlin { + srcDir "${buildDir}/generated/source/kapt/main/" + } + } + generated { java { srcDir "${projectDir}/generated/source/kapt/main/" } @@ -41,9 +48,24 @@ task buildKapt(type: Copy) { into "${projectDir}/generated" } +// Kapt hijacks anything named "compile" +task buildGenerated(type: JavaCompile) { + source = sourceSets.generated.allJava + classpath = sourceSets.generated.compileClasspath + sourceSets.main.compileClasspath + sourceSets.main.output + destinationDir = file("$buildDir/classes/generated") +} + // Remove the dependency on compile in kapt to avoid automatic kapt running - run :node-schemas:kaptKotlin explicitly. project.afterEvaluate { + jar.dependsOn.each { jar.dependsOn.remove it } + buildGenerated.dependsOn.each { buildGenerated.dependsOn.remove it } + jar.dependsOn buildGenerated + buildGenerated.dependsOn classes compileKotlin.dependsOn.remove kaptKotlin buildKapt.dependsOn kaptKotlin buildKapt.mustRunAfter kaptKotlin -} \ No newline at end of file +} + +jar { + from sourceSets.generated.output +}