Repositori Kustom & BOM
Konfigurasikan repositori Maven atau Ivy kustom dan gunakan Bill of Materials (BOM) untuk menjaga konsistensi versi dependensi.
Repositori Kustom & BOM adalah pelajaran Groovy & Gradle: JVM Automation and Build Engineering gratis di CoddyKit. Ini adalah pelajaran 3 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Groovy & Gradle: JVM Automation and Build Engineering, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Groovy & Gradle: JVM Automation and Build Engineering mencakup 4 pelajaran total.
Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.
Beyond Maven Central
By default, Gradle looks for dependencies in Maven Central. But what if your dependencies aren't there?
Custom repositories allow you to fetch libraries from other locations, like:
- Your company's private artifact server.
- Specific public repositories (e.g., Google's Maven repo for Android).
- Local file system directories.
Adding a Maven Repository
To add a custom Maven repository, you declare it in the repositories block of your build.gradle file.
Gradle will check repositories in the order they are declared, stopping at the first match.
repositories {
mavenCentral()
maven {
url 'https://repo.spring.io/milestone'
}
}Example: Google Maven Repo
Many Android libraries are hosted on Google's Maven repository. You'd add it like this:
This is crucial for projects using Google-specific libraries.
repositories {
google() // Shortcut for Google's Maven repo
mavenCentral()
}Understanding Ivy Repositories
While Maven is very common, Gradle also supports Ivy repositories. Ivy has a more flexible layout for artifacts.
You might encounter Ivy repositories in older projects or specific corporate environments.
repositories {
ivy {
url "http://repo.mycompany.com/ivy"
layout "pattern", {
artifact "[organization]/[module]/[revision]/[artifact](-[classifier])-[revision].[ext]"
}
}
}Local Directory as Repo
For testing or internal use, you can even use a local directory as a repository. This is handy for sharing artifacts within a team without a dedicated server.
Just specify the path to your local folder.
repositories {
flatDir {
dirs 'libs' // Looks for JARs directly in the 'libs' folder
}
// Or a more structured Maven-like local repo
maven {
url uri('../my-local-maven-repo')
}
}Bill of Materials (BOMs)
A Bill of Materials (BOM) is a special Maven POM file that defines a curated list of dependency versions.
It helps manage transitive dependencies and ensures consistent versions across a multi-module project or when using a suite of related libraries.
Consistency with BOMs
BOMs solve a common problem: dependency version conflicts. If multiple libraries depend on different versions of the same transitive dependency, you can end up with unpredictable behavior.
With a BOM, you declare a single "source of truth" for versions, making your build more reliable.
Importing a BOM
To use a BOM in Gradle, you declare it as a dependency using the platform() or enforcedPlatform() function. This tells Gradle to use the versions specified in the BOM.
Notice how we don't specify versions for spring-core or spring-web; the BOM handles it!
dependencies {
implementation platform('org.springframework.boot:spring-boot-dependencies:2.7.5')
// These versions are now managed by the BOM
implementation 'org.springframework:spring-core'
implementation 'org.springframework:spring-web'
}Platform vs. EnforcedPlatform
There are two ways to import a BOM:
platform(): Suggests versions. Other modules can override these versions if explicitly declared.enforcedPlatform(): Strictly enforces versions. Any explicitly declared versions for dependencies in the BOM will be overridden by the BOM's version.
Use enforcedPlatform() for strong version consistency.
Check Your Knowledge
Let's test your understanding of custom repositories and BOMs!
Custom Repos & BOMs Recap
Great job! You've learned how to:
- Configure custom Maven and Ivy repositories in Gradle.
- Understand the importance of repository order.
- Use local directories as repositories.
- Leverage Bill of Materials (BOMs) for consistent dependency version management.
- Differentiate between
platform()andenforcedPlatform().
These techniques are vital for managing complex dependency landscapes in real-world projects!
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Repositori Kustom & BOM” gratis?
Ya — teks lengkap “Repositori Kustom & BOM” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Groovy & Gradle: JVM Automation and Build Engineering, upgrade ke CoddyKit PRO. Kursus Groovy & Gradle: JVM Automation and Build Engineering mencakup 4 pelajaran total.
Apa yang akan aku pelajari di “Repositori Kustom & BOM”?
Konfigurasikan repositori Maven atau Ivy kustom dan gunakan Bill of Materials (BOM) untuk menjaga konsistensi versi dependensi. Kamu berlatih Groovy & Gradle: JVM Automation and Build Engineering dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.
Apakah aku perlu pengalaman untuk memulai Groovy & Gradle: JVM Automation and Build Engineering?
Tidak diperlukan pengalaman sebelumnya. Groovy & Gradle: JVM Automation and Build Engineering di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 3 dari 4.
Berapa lama pelajaran “Repositori Kustom & BOM” memakan waktu?
Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.
Bisakah aku menulis dan menjalankan kode dalam pelajaran Groovy & Gradle: JVM Automation and Build Engineering ini?
Ya. Setiap pelajaran Groovy & Gradle: JVM Automation and Build Engineering menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.
Semua pelajaran dalam kursus ini
- Mendeklarasikan Dependensi Proyek
- Resolusi Dependensi & Penyimpanan Tembolok
- Repositori Kustom & BOM
- Menyelesaikan Konflik Versi & Batasan Dependensi