Skip to content

Commit dc2e09f

Browse files
committed
chore: add task samples
1 parent 384d9f5 commit dc2e09f

File tree

1 file changed

+36
-0
lines changed
  • gradle/build-logic/common-plugins/src/main/kotlin/tasks

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package tasks
2+
3+
import org.gradle.api.file.DirectoryProperty
4+
import org.gradle.api.file.RegularFileProperty
5+
import org.gradle.api.tasks.*
6+
7+
/**
8+
* A sample [JavaExec] task that executes class from runtime classpath is as follows:
9+
* ```kotlin
10+
* val execTask by registering(JavaExec::class) {
11+
* doFirst { ... }
12+
* group = "build"
13+
* mainClass = "app.Main"
14+
* classpath = sourceSets.main.get().runtimeClasspath
15+
* args = listOf(....)
16+
* outputs.dir(outDir)
17+
* doLast { }
18+
* finalizedBy(copyTask)
19+
* }
20+
* ```
21+
*/
22+
@CacheableTask
23+
abstract class ExecTask : JavaExec() {
24+
25+
@get:InputFile
26+
@get:PathSensitive(PathSensitivity.RELATIVE)
27+
abstract val sourceFile: RegularFileProperty
28+
29+
@get:OutputDirectory abstract val outputDir: DirectoryProperty
30+
31+
init {
32+
group = "build"
33+
mainClass.set("app.Main")
34+
argumentProviders.add { listOf(outputDir.get().asFile.path, sourceFile.get().asFile.path) }
35+
}
36+
}

0 commit comments

Comments
 (0)