From 702ceb5b98386acbe1428617ea89fbfffd39ac23 Mon Sep 17 00:00:00 2001 From: Eric Deandrea Date: Thu, 19 Mar 2020 14:04:50 -0400 Subject: [PATCH] Generated sources aren't added as source dirs in non-Java projects (#19) Fixes #18 --- gradle/wrapper/gradle-wrapper.properties | 2 +- .../edeandrea/xjcplugin/plugin/XjcPlugin.kt | 26 +++++++++++++++++-- .../github/edeandrea/xjcplugin/type/Xjc.kt | 4 +-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8422670..84a9066 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/kotlin/com/github/edeandrea/xjcplugin/plugin/XjcPlugin.kt b/src/main/kotlin/com/github/edeandrea/xjcplugin/plugin/XjcPlugin.kt index a021c47..865d3d2 100644 --- a/src/main/kotlin/com/github/edeandrea/xjcplugin/plugin/XjcPlugin.kt +++ b/src/main/kotlin/com/github/edeandrea/xjcplugin/plugin/XjcPlugin.kt @@ -114,8 +114,30 @@ class XjcPlugin : Plugin { it.additionalXjcCommandLineArgs = additionalXjcCommandLineArgs } - val sourceSetNameTaskName = if (sourceSetName == "main") "compileJava" else "compile${sourceSetName.capitalize()}Java" - project.tasks.getByName(sourceSetNameTaskName).dependsOn(xjcTask) + linkTasksToPreCompile(sourceSetName, project, xjcTask) + } + } + + private fun linkTaskToPreCompile(sourceSetName: String, project: Project, xjcTask: Xjc, language: String) { + val sourceSetNameTaskName = if (sourceSetName == "main") "compile${language}" else "compile${sourceSetName.capitalize()}${language}" + project.tasks.getByName(sourceSetNameTaskName).dependsOn(xjcTask) + } + + private fun linkTasksToPreCompile(sourceSetName: String, project: Project, xjcTask: Xjc) { + project.pluginManager.withPlugin("java") { + linkTaskToPreCompile(sourceSetName, project, xjcTask, "Java") + } + + project.pluginManager.withPlugin("groovy") { + linkTaskToPreCompile(sourceSetName, project, xjcTask, "Groovy") + } + + project.pluginManager.withPlugin("scala") { + linkTaskToPreCompile(sourceSetName, project, xjcTask, "Scala") + } + + project.pluginManager.withPlugin("kotlin") { + linkTaskToPreCompile(sourceSetName, project, xjcTask, "Kotlin") } } diff --git a/src/main/kotlin/com/github/edeandrea/xjcplugin/type/Xjc.kt b/src/main/kotlin/com/github/edeandrea/xjcplugin/type/Xjc.kt index 266e1bd..173b2e9 100644 --- a/src/main/kotlin/com/github/edeandrea/xjcplugin/type/Xjc.kt +++ b/src/main/kotlin/com/github/edeandrea/xjcplugin/type/Xjc.kt @@ -159,7 +159,7 @@ open class Xjc : DefaultTask() { } private fun processXjc(language: String, schemaFile: File?, schemaFiles: FileCollection?) { - val optionsMap = mutableMapOf( + val optionsMap: MutableMap = mutableMapOf( "destdir" to this.schemaGenDir.absolutePath, "extension" to true, "language" to language @@ -170,7 +170,7 @@ open class Xjc : DefaultTask() { } if (this.bindingFile != null) { - optionsMap["binding"] = this.bindingFile + optionsMap["binding"] = this.bindingFile!! } if (this.additionalXjcOptions.isNotEmpty()) {