Skip to content

Commit 49ea922

Browse files
authored
Merge pull request #46 from sgrimm/gradle7
Make plugin work under Gradle 7
2 parents 22f8f46 + f15ebd6 commit 49ea922

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.springdoc.openapi.gradle.plugin
2+
3+
import com.github.jengelman.gradle.plugins.processes.tasks.Fork
4+
import groovy.lang.MetaClass
5+
import org.codehaus.groovy.runtime.InvokerHelper
6+
import org.gradle.api.tasks.Internal
7+
import org.gradle.process.CommandLineArgumentProvider
8+
9+
/**
10+
* Extends the Fork task from the gradle-processes plugin to be compatible with Gradle 7.
11+
* The functionality of the class remains exactly the same; it was just missing an annotation
12+
* on the [getArgumentProviders] method and the annotation is mandatory in Gradle 7.
13+
*
14+
* Since the original class is written in Groovy, we also need to implement some internal
15+
* Groovy methods that get added to Groovy classes via bytecode manipulation.
16+
*/
17+
open class AnnotatedFork : Fork() {
18+
private var metaClass: MetaClass? = null
19+
20+
override fun invokeMethod(method: String?, args: Any?): Any? {
21+
return InvokerHelper.invokeMethod(this, method, args)
22+
}
23+
24+
override fun getProperty(property: String?): Any? {
25+
return InvokerHelper.getProperty(this, property)
26+
}
27+
28+
override fun getMetaClass(): MetaClass? {
29+
if (metaClass == null) {
30+
metaClass = InvokerHelper.getMetaClass(javaClass)
31+
}
32+
return metaClass
33+
}
34+
35+
override fun setMetaClass(newMetaClass: MetaClass?) {
36+
metaClass = newMetaClass
37+
}
38+
39+
@Internal
40+
override fun getArgumentProviders(): MutableList<CommandLineArgumentProvider>? {
41+
return super.getArgumentProviders()
42+
}
43+
}

Diff for: src/main/kotlin/org/springdoc/openapi/gradle/plugin/OpenApiGradlePlugin.kt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.springdoc.openapi.gradle.plugin
22

3-
import com.github.jengelman.gradle.plugins.processes.tasks.Fork
43
import org.gradle.api.Plugin
54
import org.gradle.api.Project
65
import org.gradle.api.logging.Logging
@@ -26,7 +25,7 @@ open class OpenApiGradlePlugin : Plugin<Project> {
2625
}
2726

2827
// Create a forked version spring boot run task
29-
val forkedSpringBoot = project.tasks.register(FORKED_SPRING_BOOT_RUN_TASK_NAME, Fork::class.java) { fork ->
28+
val forkedSpringBoot = project.tasks.register(FORKED_SPRING_BOOT_RUN_TASK_NAME, AnnotatedFork::class.java) { fork ->
3029
fork.dependsOn(bootJarTask)
3130

3231
fork.onlyIf {

0 commit comments

Comments
 (0)