0Pricing
Groovy & Gradle: JVM Automation and Build Engineering · บทเรียน

งานแบบเพิ่มทีละน้อยและการตรวจสอบความเป็นปัจจุบัน

ทำให้งานที่กำหนดเองรวดเร็วและถูกต้องด้วยการประกาศอินพุตและเอาต์พุต เพื่อให้ Gradle ข้ามงานที่เป็นปัจจุบันอยู่แล้ว

งานแบบเพิ่มทีละน้อยและการตรวจสอบความเป็นปัจจุบัน เป็นบทเรียน Groovy & Gradle: JVM Automation and Build Engineering ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Groovy & Gradle: JVM Automation and Build Engineering และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Groovy & Gradle: JVM Automation and Build Engineering มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Why Tasks Get Skipped

Gradle is fast because it does not redo work. If a task ran before and nothing it depends on changed, Gradle marks it UP-TO-DATE and skips it. You enable this by declaring inputs and outputs.

Inputs and Outputs

Every task can declare what it reads (inputs) and what it produces (outputs). Gradle hashes them to decide whether to run.

Declaring File Inputs

Annotate or register input files so Gradle watches them for changes.

tasks.register('process') {
    inputs.file 'data/in.txt'
    outputs.file 'build/out.txt'
}

The Up-to-Date Decision

On each run Gradle compares current input/output hashes to the last run. If both match, the task is skipped; if any input changed, it re-runs.

Property Inputs

Non-file inputs (a flag, a version string) are declared with inputs.property so changing them also invalidates the cache.

tasks.register('gen') {
    inputs.property 'version', project.version
    outputs.dir 'build/gen'
}

Custom Task Types

For reusable logic, write a task class with annotated properties: @InputFile, @OutputFile, @Input. Gradle reads the annotations automatically.

An Annotated Task Class

Annotations tell Gradle how to track each property without manual inputs/outputs wiring.

class Copy extends DefaultTask {
    @InputFile File source
    @OutputFile File dest
    @TaskAction void run() { dest.text = source.text }
}

Incremental Inputs

For tasks over many files, @Incremental inputs let the action process only the files that actually changed since last run.

The Build Cache

Beyond up-to-date checks, the build cache can reuse outputs from a previous run on any machine, keyed by the same input hashes — huge for CI.

org.gradle.caching=true

Common Mistakes

Forgetting to declare an input is the classic bug: Gradle skips a task that should have re-run, producing stale output. Always declare every input that affects the result.

Forcing a Rerun

To verify caching or work around a stale state, run with --rerun-tasks to ignore up-to-date checks for one build, or use outputs.upToDateWhen { false } to mark a task as never up to date.

gradle build --rerun-tasks

Quick Check

Test your incremental build knowledge.

Recap

You learned to build fast, correct tasks:

  • Gradle skips tasks whose inputs and outputs are unchanged
  • Declare files with inputs.file/outputs.file and values with inputs.property
  • Custom task classes use @InputFile/@OutputFile annotations
  • The build cache reuses outputs across machines
  • Undeclared inputs cause stale, incorrect skips

คำถามที่พบบ่อย

บทเรียน “งานแบบเพิ่มทีละน้อยและการตรวจสอบความเป็นปัจจุบัน” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “งานแบบเพิ่มทีละน้อยและการตรวจสอบความเป็นปัจจุบัน” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Groovy & Gradle: JVM Automation and Build Engineering ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Groovy & Gradle: JVM Automation and Build Engineering มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “งานแบบเพิ่มทีละน้อยและการตรวจสอบความเป็นปัจจุบัน”

ทำให้งานที่กำหนดเองรวดเร็วและถูกต้องด้วยการประกาศอินพุตและเอาต์พุต เพื่อให้ Gradle ข้ามงานที่เป็นปัจจุบันอยู่แล้ว คุณปฏิบัติ Groovy & Gradle: JVM Automation and Build Engineering ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Groovy & Gradle: JVM Automation and Build Engineering หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Groovy & Gradle: JVM Automation and Build Engineering บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “งานแบบเพิ่มทีละน้อยและการตรวจสอบความเป็นปัจจุบัน” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Groovy & Gradle: JVM Automation and Build Engineering นี้ได้ไหม

ได้ บทเรียน Groovy & Gradle: JVM Automation and Build Engineering ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. การกำหนดงานแบบกำหนดเอง
  2. ชนิดงานและการดำเนินการ
  3. คุณสมบัติและการกำหนดค่างาน
  4. งานแบบเพิ่มทีละน้อยและการตรวจสอบความเป็นปัจจุบัน
← กลับไปที่ Groovy & Gradle: JVM Automation and Build Engineering