|
1 | 1 | package plugins
|
2 | 2 |
|
3 |
| -import org.gradle.jvm.tasks.Jar |
4 |
| -import org.gradle.tooling.* |
5 | 3 | import java.io.*
|
6 | 4 | import java.util.concurrent.*
|
7 | 5 | import java.util.spi.*
|
| 6 | +import org.gradle.jvm.tasks.Jar |
| 7 | +import org.gradle.tooling.* |
8 | 8 |
|
9 | 9 | plugins {
|
10 |
| - java |
| 10 | + java |
| 11 | +} |
| 12 | + |
| 13 | +// Print all the tasks |
| 14 | +gradle.taskGraph.whenReady { |
| 15 | + allTasks.forEachIndexed { index, task -> |
| 16 | + println("${index + 1}. ${task.name}") |
| 17 | + } |
11 | 18 | }
|
12 | 19 |
|
13 | 20 | tasks {
|
14 | 21 |
|
15 |
| - val printModuleDeps by registering { |
16 |
| - description = "Print Java Platform Module dependencies of the application." |
17 |
| - group = LifecycleBasePlugin.BUILD_TASK_NAME |
| 22 | + val printModuleDeps by registering { |
| 23 | + description = "Print Java Platform Module dependencies of the application." |
| 24 | + group = LifecycleBasePlugin.BUILD_TASK_NAME |
18 | 25 |
|
19 |
| - doLast { |
20 |
| - val uberJar = named("shadowJar", Jar::class) |
21 |
| - val jarFile = uberJar.get().archiveFile.get().asFile |
| 26 | + doLast { |
| 27 | + val uberJar = named("shadowJar", Jar::class) |
| 28 | + val jarFile = uberJar.get().archiveFile.get().asFile |
22 | 29 |
|
23 |
| - val jdeps = ToolProvider.findFirst("jdeps").orElseGet { error("") } |
24 |
| - val out = StringWriter() |
25 |
| - val pw = PrintWriter(out) |
26 |
| - jdeps.run(pw, pw, "--print-module-deps", "--ignore-missing-deps", jarFile.absolutePath) |
| 30 | + val jdeps = ToolProvider.findFirst("jdeps").orElseGet { error("") } |
| 31 | + val out = StringWriter() |
| 32 | + val pw = PrintWriter(out) |
| 33 | + jdeps.run(pw, pw, "--print-module-deps", "--ignore-missing-deps", jarFile.absolutePath) |
27 | 34 |
|
28 |
| - val modules = out.toString() |
29 |
| - println(modules) |
30 |
| - } |
31 |
| - dependsOn("shadowJar") |
| 35 | + val modules = out.toString() |
| 36 | + println(modules) |
32 | 37 | }
|
| 38 | + dependsOn("shadowJar") |
| 39 | + } |
33 | 40 |
|
34 |
| - val copyTemplates by registering(Copy::class) { |
35 |
| - description = "Generate template classes." |
36 |
| - group = LifecycleBasePlugin.BUILD_TASK_NAME |
37 |
| - |
38 |
| - val configuredVersion = providers |
39 |
| - .gradleProperty("version") |
40 |
| - .forUseAtConfigurationTime() |
41 |
| - .get() |
42 |
| - |
43 |
| - val props = project.extra.properties |
44 |
| - props["projectVersion"] = project.version |
45 |
| - props["configuredVersion"] = configuredVersion |
46 |
| - props["kotlinVersion"] = System.getProperty("kotlinVersion") |
47 |
| - |
48 |
| - val debug: String by project |
49 |
| - if (debug.toBoolean()) { |
50 |
| - props.forEach { (t, u) -> |
51 |
| - println("%1\$-42s --> %2\$s".format(t, u)) |
52 |
| - } |
53 |
| - } |
54 |
| - |
55 |
| - filteringCharset = "UTF-8" |
56 |
| - inputs.property("buildversions", props.hashCode()) |
57 |
| - from(project.projectDir.resolve("src/main/templates")) |
58 |
| - into(project.buildDir.resolve("generated-sources/templates/kotlin/main")) |
59 |
| - exclude { it.name.startsWith("jte") } |
60 |
| - expand(props) |
| 41 | + val copyTemplates by registering(Copy::class) { |
| 42 | + description = "Generate template classes." |
| 43 | + group = LifecycleBasePlugin.BUILD_TASK_NAME |
| 44 | + |
| 45 | + val configuredVersion = providers |
| 46 | + .gradleProperty("version") |
| 47 | + .forUseAtConfigurationTime() |
| 48 | + .get() |
| 49 | + |
| 50 | + val props = project.extra.properties |
| 51 | + props["projectVersion"] = project.version |
| 52 | + props["configuredVersion"] = configuredVersion |
| 53 | + props["kotlinVersion"] = System.getProperty("kotlinVersion") |
| 54 | + |
| 55 | + val debug: String by project |
| 56 | + if (debug.toBoolean()) { |
| 57 | + props.forEach { (t, u) -> |
| 58 | + println("%1\$-42s --> %2\$s".format(t, u)) |
| 59 | + } |
61 | 60 | }
|
62 | 61 |
|
63 |
| - /** |
64 |
| - * Dev task that does both the continuous compile and run. |
65 |
| - */ |
66 |
| - val dev by registering { |
67 |
| - description = "A task to continuous compile and run" |
68 |
| - group = LifecycleBasePlugin.BUILD_GROUP |
69 |
| - |
70 |
| - doLast { |
71 |
| - val continuousCompile = forkTask("classes", "-t") |
72 |
| - val run = forkTask("run") |
73 |
| - CompletableFuture.allOf(continuousCompile, run).join() |
74 |
| - } |
| 62 | + filteringCharset = "UTF-8" |
| 63 | + inputs.property("buildversions", props.hashCode()) |
| 64 | + from(project.projectDir.resolve("src/main/templates")) |
| 65 | + into(project.buildDir.resolve("generated-sources/templates/kotlin/main")) |
| 66 | + exclude { it.name.startsWith("jte") } |
| 67 | + expand(props) |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * Dev task that does both the continuous compile and run. |
| 72 | + */ |
| 73 | + val dev by registering { |
| 74 | + description = "A task to continuous compile and run" |
| 75 | + group = LifecycleBasePlugin.BUILD_GROUP |
| 76 | + |
| 77 | + doLast { |
| 78 | + val continuousCompile = forkTask("classes", "-t") |
| 79 | + val run = forkTask("run") |
| 80 | + CompletableFuture.allOf(continuousCompile, run).join() |
75 | 81 | }
|
| 82 | + } |
76 | 83 | }
|
77 | 84 |
|
78 | 85 | /**
|
79 | 86 | * Fork a new gradle [task] with given [args]
|
80 | 87 | */
|
81 | 88 | fun forkTask(task: String, vararg args: String) = CompletableFuture.supplyAsync {
|
82 |
| - GradleConnector.newConnector() |
83 |
| - .forProjectDirectory(project.projectDir) |
84 |
| - .connect() |
85 |
| - .use { |
86 |
| - it.newBuild() |
87 |
| - .addArguments(*args) |
88 |
| - .addJvmArguments( |
89 |
| - "--add-opens", |
90 |
| - "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED" |
91 |
| - ) |
92 |
| - .forTasks(task) |
93 |
| - .setStandardError(System.err) |
94 |
| - .setStandardInput(System.`in`) |
95 |
| - .setStandardOutput(System.out) |
96 |
| - .run() |
97 |
| - } |
| 89 | + GradleConnector.newConnector() |
| 90 | + .forProjectDirectory(project.projectDir) |
| 91 | + .connect() |
| 92 | + .use { |
| 93 | + it.newBuild() |
| 94 | + .addArguments(*args) |
| 95 | + .addJvmArguments( |
| 96 | + "--add-opens", |
| 97 | + "jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED" |
| 98 | + ) |
| 99 | + .forTasks(task) |
| 100 | + .setStandardError(System.err) |
| 101 | + .setStandardInput(System.`in`) |
| 102 | + .setStandardOutput(System.out) |
| 103 | + .run() |
| 104 | + } |
98 | 105 | }
|
0 commit comments