Skip to content

Commit 583c21b

Browse files
nbrugger-tgmfrantuma
authored andcommitted
feat(gradle-plugin): enable lazy configuration
changes: - enable lazy evaluation by - replacing all Task configurations with gradles Property types - using `register` instead of `create` to register the task - remove wrongly set task dependencies that can cause circular dependencies. Task dependencies are now inferred by the set classpath. When gradle detects that an output of a task (like compileJava) is used an automatic dependency is formed and `resolve` will always execute compileJava first. The advantage is that this is dynamic. If one does NOT want `compileJava` to be executed it won't be as soon as nothing of compileJava is on the configured classpath
1 parent fbcc02f commit 583c21b

File tree

2 files changed

+300
-295
lines changed

2 files changed

+300
-295
lines changed

modules/swagger-gradle-plugin/src/main/java/io/swagger/v3/plugins/gradle/SwaggerPlugin.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
import org.gradle.api.Action;
55
import org.gradle.api.Plugin;
66
import org.gradle.api.Project;
7-
import org.gradle.api.Task;
87
import org.gradle.api.artifacts.Configuration;
98
import org.gradle.api.artifacts.DependencySet;
9+
import org.gradle.api.tasks.SourceSetContainer;
10+
import org.gradle.api.tasks.TaskProvider;
1011

1112
public class SwaggerPlugin implements Plugin<Project> {
1213
public void apply(Project project) {
@@ -21,24 +22,20 @@ public void execute(DependencySet dependencies) {
2122
dependencies.add(project.getDependencies().create("javax.servlet:javax.servlet-api:3.1.0"));
2223
}
2324
});
24-
Task task = project.getTasks().create("resolve", ResolveTask.class);
25-
((ResolveTask)task).setBuildClasspath(config);
26-
27-
try {
28-
if (project.getTasks().findByPath("classes") != null) {
29-
task.dependsOn("classes");
30-
}
31-
if (project.getTasks().findByPath("compileJava") != null) {
32-
task.dependsOn("compileJava");
33-
}
34-
if (project.getTasks().findByPath("compileTestJava") != null) {
35-
task.dependsOn("compileTestJava");
36-
}
37-
if (project.getTasks().findByPath("testClasses") != null) {
38-
task.dependsOn("testClasses");
39-
}
40-
} catch (Exception e) {
41-
project.getLogger().warn("Exception in task dependencies: " + e.getMessage(), e);
42-
}
25+
TaskProvider<ResolveTask> lazyTask = project.getTasks().register("resolve", ResolveTask.class,task -> {
26+
task.buildClasspath.setFrom(config);
27+
task.classpath.setFrom(project.getExtensions().findByType(SourceSetContainer.class).getByName("main").getRuntimeClasspath().getFiles());
28+
task.prettyPrint.convention(false);
29+
task.readAllResources.convention(true);
30+
task.outputFormat.convention(ResolveTask.Format.JSON);
31+
task.skip.convention(false);
32+
task.encoding.convention("UTF-8");
33+
task.sortOutput.convention(Boolean.FALSE);
34+
task.alwaysResolveAppPath.convention(Boolean.FALSE);
35+
task.skipResolveAppPath.convention(Boolean.FALSE);
36+
task.openAPI31.convention(false);
37+
task.convertToOpenAPI31.convention(false);
38+
task.outputDir.convention(project.getLayout().getBuildDirectory().dir("swagger"));
39+
});
4340
}
4441
}

0 commit comments

Comments
 (0)