Skip to content

Commit

Permalink
Generated sources aren't added as source dirs in non-Java projects (#19)
Browse files Browse the repository at this point in the history
Fixes #18
  • Loading branch information
edeandrea authored Mar 19, 2020
1 parent 1a2cc00 commit 702ceb5
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
26 changes: 24 additions & 2 deletions src/main/kotlin/com/github/edeandrea/xjcplugin/plugin/XjcPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,30 @@ class XjcPlugin : Plugin<Project> {
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")
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/github/edeandrea/xjcplugin/type/Xjc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ open class Xjc : DefaultTask() {
}

private fun processXjc(language: String, schemaFile: File?, schemaFiles: FileCollection?) {
val optionsMap = mutableMapOf(
val optionsMap: MutableMap<String, Any> = mutableMapOf(
"destdir" to this.schemaGenDir.absolutePath,
"extension" to true,
"language" to language
Expand All @@ -170,7 +170,7 @@ open class Xjc : DefaultTask() {
}

if (this.bindingFile != null) {
optionsMap["binding"] = this.bindingFile
optionsMap["binding"] = this.bindingFile!!
}

if (this.additionalXjcOptions.isNotEmpty()) {
Expand Down

0 comments on commit 702ceb5

Please sign in to comment.