Skip to content

Commit 5102443

Browse files
committed
chore: print task graph
1 parent 288d8f2 commit 5102443

File tree

1 file changed

+79
-72
lines changed

1 file changed

+79
-72
lines changed
Lines changed: 79 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,105 @@
11
package plugins
22

3-
import org.gradle.jvm.tasks.Jar
4-
import org.gradle.tooling.*
53
import java.io.*
64
import java.util.concurrent.*
75
import java.util.spi.*
6+
import org.gradle.jvm.tasks.Jar
7+
import org.gradle.tooling.*
88

99
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+
}
1118
}
1219

1320
tasks {
1421

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
1825

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
2229

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)
2734

28-
val modules = out.toString()
29-
println(modules)
30-
}
31-
dependsOn("shadowJar")
35+
val modules = out.toString()
36+
println(modules)
3237
}
38+
dependsOn("shadowJar")
39+
}
3340

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+
}
6160
}
6261

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()
7581
}
82+
}
7683
}
7784

7885
/**
7986
* Fork a new gradle [task] with given [args]
8087
*/
8188
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+
}
98105
}

0 commit comments

Comments
 (0)