@@ -32,7 +32,6 @@ open class SwaggerCodeGenPlugin : Plugin<Project> {
32
32
val configsExt = project.extensions.create(SWAGGER_TASK , SwaggerCodeGenConfig ::class .java)
33
33
autoHookJava(project, configsExt)
34
34
autoHookKotlin(project, configsExt)
35
- autoHookKotlin(project, configsExt, true )
36
35
}
37
36
38
37
/* *
@@ -69,41 +68,31 @@ open class SwaggerCodeGenPlugin : Plugin<Project> {
69
68
}
70
69
71
70
/* *
72
- * Auto-hooks openApi generation to project that contain compile task [COMPILE_KOTLIN] or [COMPILE_KOTLIN_JVM] .
73
- * Finds the task and crates java generator task for it with dependency.
71
+ * Auto-hooks openApi generation to project that contain Kotlin compile task.
72
+ * Finds the task and creates java generator task for it with dependency.
74
73
*
75
74
* @param project used to search for compile tasks
76
75
* @param configsExt swagger gen config
77
76
*/
78
- private fun autoHookKotlin (
79
- project : Project ,
80
- configsExt : SwaggerCodeGenConfig ,
81
- isMpp : Boolean = false
82
- ) {
83
- var hooked = false
77
+ private fun autoHookKotlin (project : Project , configsExt : SwaggerCodeGenConfig ) {
84
78
project.afterEvaluate {
85
79
if (configsExt.autoHook) {
86
- val compileTaskName = if (isMpp) {
87
- COMPILE_KOTLIN_JVM
88
- } else {
89
- COMPILE_KOTLIN
80
+ val generators = configsExt.configs.mapNotNull { taskConfig ->
81
+ createGenerator(
82
+ project,
83
+ LANGUAGE_KOTLIN ,
84
+ configsExt,
85
+ taskConfig
86
+ )
90
87
}
91
- project.getTasksByName(compileTaskName, false ).firstOrNull()?.let { compileKotlin ->
92
- configsExt.configs.forEach { taskConfig ->
93
- createGenerator(
94
- project,
95
- LANGUAGE_KOTLIN ,
96
- configsExt,
97
- taskConfig
98
- )?.let { task ->
99
- compileKotlin.dependsOn(task)
100
- }
101
- }
102
- hooked = true
88
+
89
+ val compileTasks = project.kotlinCompileTasks()
90
+ logger.info(" Kotlin auto-hooked: ${compileTasks.isNotEmpty()} " )
91
+ compileTasks.all { task ->
92
+ task.dependsOn(generators)
103
93
}
104
94
}
105
95
}
106
- logger.info(" Kotlin (isMpp: $isMpp ) auto-hooked: $hooked " )
107
96
}
108
97
109
98
/* *
0 commit comments