Zadania przyrostowe i sprawdzanie aktualności
Twórz szybkie i poprawne zadania niestandardowe, deklarując dane wejściowe i wyjściowe, aby Gradle mógł pomijać pracę, która jest już aktualna.
Zadania przyrostowe i sprawdzanie aktualności 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.
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=trueCommon 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-tasksQuick 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.fileand values withinputs.property - Custom task classes use
@InputFile/@OutputFileannotations - The build cache reuses outputs across machines
- Undeclared inputs cause stale, incorrect skips
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 „Zadania przyrostowe i sprawdzanie aktualności” jest bezpłatna?
Tak — pełny tekst „Zadania przyrostowe i sprawdzanie aktualności” 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 „Zadania przyrostowe i sprawdzanie aktualności”?
Twórz szybkie i poprawne zadania niestandardowe, deklarując dane wejściowe i wyjściowe, aby Gradle mógł pomijać pracę, która jest już aktualna. Ć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 „Zadania przyrostowe i sprawdzanie aktualności”?
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
- Definiowanie niestandardowych zadań
- Typy i akcje zadań
- Właściwości i konfiguracja zadań
- Zadania przyrostowe i sprawdzanie aktualności