Groovy & Gradle: JVM Automation and Build Engineering · Lekcja

Kompilacje przyrostowe oraz dane wejściowe i wyjściowe zadań

Poznaj sposób, w jaki Gradle pomija wykonaną już pracę, śledząc dane wejściowe i wyjściowe zadań, oraz naucz się poprawnie tworzyć zadania niestandardowe o działaniu przyrostowym i możliwości buforowania.

Lekcja 4 z 413 kroki

Kompilacje przyrostowe oraz dane wejściowe i wyjściowe zadań to bezpłatna lekcja Groovy & Gradle: JVM Automation and Build Engineering na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Groovy & Gradle: JVM Automation and Build Engineering, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Groovy & Gradle: JVM Automation and Build Engineering zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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
Bezpłatny start

Ucz się Groovy dzięki korepetycjom AI — za darmo

Pisz i uruchamiaj kod w przeglądarce, otrzymuj natychmiastową pomoc od korepetytora AI dostępnego 24/7 i kontynuuj naukę w sieci lub w aplikacji.

Kursy
12
Lekcje
48

Często zadawane pytania

Czy lekcja „Kompilacje przyrostowe oraz dane wejściowe i wyjściowe zadań” jest bezpłatna?

Tak — pełny tekst „Kompilacje przyrostowe oraz dane wejściowe i wyjściowe zadań” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Groovy & Gradle: JVM Automation and Build Engineering, przejdź na CoddyKit PRO. Kurs Groovy & Gradle: JVM Automation and Build Engineering zawiera 4 lekcji w sumie.

Co nauczysz się w „Kompilacje przyrostowe oraz dane wejściowe i wyjściowe zadań”?

Poznaj sposób, w jaki Gradle pomija wykonaną już pracę, śledząc dane wejściowe i wyjściowe zadań, oraz naucz się poprawnie tworzyć zadania niestandardowe o działaniu przyrostowym i możliwości buforow… Ćwiczysz Groovy & Gradle: JVM Automation and Build Engineering z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Groovy & Gradle: JVM Automation and Build Engineering?

Nie wymagamy żadnego doświadczenia. Groovy & Gradle: JVM Automation and Build Engineering w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.

Ile czasu zajmuje lekcja „Kompilacje przyrostowe oraz dane wejściowe i wyjściowe zadań”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Groovy & Gradle: JVM Automation and Build Engineering?

Tak. Każda lekcja Groovy & Gradle: JVM Automation and Build Engineering zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Pamięć podręczna kompilacji i Daemon
  2. Profilowanie i debugowanie kompilacji
  3. Wykonywanie równoległe i konfiguracja
  4. Kompilacje przyrostowe oraz dane wejściowe i wyjściowe zadań
← Powrót do Groovy & Gradle: JVM Automation and Build Engineering