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

การสร้างแบบเพิ่มทีละน้อยและอินพุต/เอาต์พุตของงาน

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

บทเรียน 4 จาก 413 ขั้นตอน

การสร้างแบบเพิ่มทีละน้อยและอินพุต/เอาต์พุตของงาน เป็นบทเรียน 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 บทเรียน

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

What Makes a Build Fast?

The fastest task is the one Gradle does not run. Incremental builds let Gradle skip tasks whose inputs and outputs have not changed since the last run.

UP-TO-DATE Checks

When a task reports UP-TO-DATE, Gradle compared the current inputs/outputs against a stored snapshot and found no change, so it skipped execution.

gradle compileJava
> Task :compileJava UP-TO-DATE

Declaring Inputs

For Gradle to track a custom task, annotate its inputs. Files, directories, and simple properties all qualify.

@InputFile
File getSource() { return source }

Declaring Outputs

Outputs tell Gradle what the task produces. If an output is deleted or changed, the task reruns.

@OutputFile
File getReport() { return report }

Property Inputs

Non-file inputs use @Input. Changing the value invalidates the cached result.

@Input
String getGreeting() { return greeting }

Why Untracked Tasks Always Run

A task with no declared inputs and outputs has nothing to compare, so Gradle runs it every time. Always declare them to gain incrementality.

Incremental Task Action

Advanced tasks process only the changed files using InputChanges, instead of reprocessing everything.

tasks.register("process", ProcessTask) {
    // action receives InputChanges to query added/modified files
}

Build Cache Synergy

Correctly declared inputs/outputs also unlock the build cache: identical inputs across machines reuse stored outputs.

org.gradle.caching=true

Diagnosing Re-runs

Use the --info flag to see why a task was not UP-TO-DATE. Gradle prints which input or output changed.

gradle build --info

Common Pitfalls

Watch out for inputs that change every run:

  • Timestamps embedded in outputs
  • Absolute paths in inputs
  • Reading system time or random values

These break incrementality.

Normalizing Inputs

Use path sensitivity to ignore irrelevant differences, e.g. classpath order, so equivalent inputs hash the same.

@Classpath
FileCollection getDependencies() { return deps }

Quick Check

Test your understanding of incremental builds.

Recap

You learned incremental builds:

  • UP-TO-DATE means inputs/outputs were unchanged
  • Annotate with @Input, @InputFile, @OutputFile
  • Undeclared tasks always run
  • Avoid timestamps and absolute paths that break tracking
  • Correct declarations also enable the build cache
เริ่มต้นได้ฟรี

เรียนรู้ Groovy ด้วย AI tutor — ฟรี

เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป

คอร์ส
12
บทเรียน
48

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

บทเรียน “การสร้างแบบเพิ่มทีละน้อยและอินพุต/เอาต์พุตของงาน” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การสร้างแบบเพิ่มทีละน้อยและอินพุต/เอาต์พุตของงาน” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ 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