-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Understanding Gradle #36 – Task Actions | ||
|
||
**👇 click thumbnail to watch video** | ||
|
||
[<img src="https://onepiecesoftware.github.io/img/videos/36.png" width="640">](https://www.youtube.com/watch?v=7ueAnM7ADm4&list=PLWQK2ZdV4Yl2k2OmC_gsjDpdIBTN0qqkE) | ||
|
||
Tweak what a task is doing by adding or modifying task actions. | ||
|
||
## Explore this sample | ||
|
||
This sample is best explored in [IntelliJ IDEA](https://www.jetbrains.com/idea/download). | ||
Open **`36_Task_Actions/my-project`** in IDEA and confirm with _Trust Project_. | ||
|
||
## Further readings | ||
|
||
* [Configuring Tasks](https://docs.gradle.org/current/userguide/more_about_tasks.html#sec:configuring_tasks) | ||
* ['doFirst' / 'doLast' and Configuration Cache](https://docs.gradle.org/current/userguide/common_caching_problems.html#suggestions_for_authoring_your_build) | ||
|
||
## Need Gradle support? | ||
|
||
Contact me, if you need help with Gradle: [onepiece.Software](https://onepiece.software). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} |
15 changes: 15 additions & 0 deletions
15
36_Task_Actions/my-build-logic/java-plugins/src/main/kotlin/PrintVersion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.provider.Property | ||
import org.gradle.api.tasks.Input | ||
import org.gradle.api.tasks.TaskAction | ||
|
||
abstract class PrintVersion : DefaultTask() { | ||
|
||
@get:Input | ||
abstract val version: Property<String> | ||
|
||
@TaskAction | ||
fun print() { | ||
println("Version: ${version.get()}") | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
36_Task_Actions/my-build-logic/java-plugins/src/main/kotlin/my-java-application.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
id("application") | ||
} | ||
|
||
tasks.compileJava { | ||
actions.clear() // Remove compile action from JavaCompile task | ||
doFirst { | ||
println("Number of task actions: " + actions.size) | ||
} | ||
doLast { | ||
this as JavaCompile | ||
Runtime.getRuntime().exec( // Add our own 'java compile' implementation | ||
"javac ${source.asPath} -d ${destinationDirectory.get().asFile}").waitFor() | ||
println("Compilation finished: ${inputs.sourceFiles.asPath}") | ||
} | ||
} | ||
|
||
tasks.register<PrintVersion>("printVersion") { | ||
version = project.version as String | ||
} | ||
|
||
tasks.register("printVersionDynamic") { | ||
inputs.property("version", project.version) | ||
doLast { | ||
// Task action / execution time code | ||
println("Version: ${inputs.properties["version"]}") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
dependencyResolutionManagement { | ||
repositories.gradlePluginPortal() | ||
} | ||
|
||
include("java-plugins") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
plugins { | ||
id("my-java-application") | ||
} | ||
|
||
version = "1.0" | ||
|
||
application { | ||
mainClass = "org.example.app.App" | ||
} |
8 changes: 8 additions & 0 deletions
8
36_Task_Actions/my-project/app/src/main/java/org/example/app/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.example.app; | ||
|
||
public class App { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Hello World \uD83D\uDE80"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.gradle.configuration-cache=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Locations of Gradle plugins | ||
pluginManagement { | ||
repositories.gradlePluginPortal() | ||
includeBuild("../my-build-logic") | ||
} | ||
|
||
// Location of other components | ||
dependencyResolutionManagement { | ||
repositories.mavenCentral() | ||
} | ||
|
||
include("app") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters