Halaman ini menjelaskan cara menambahkan, melihat, dan menghapus paket Java.
Jika Anda ingin menggunakan sbt sebagai alat build untuk Scala dan Java, bukan menggunakan Maven atau Gradle, ada plugin sbt yang dibuat komunitas tersedia. Dokumentasi ini tidak menjelaskan konfigurasi atau penggunaan klien Scala.
Sebelum memulai
- Jika repositori target tidak ada, buat repositori baru.
- Pastikan Anda memiliki izin yang diperlukan untuk repositori.
- Pastikan Anda telah mengonfigurasi autentikasi. Jika Anda menggunakan token akses, pastikan Anda memperbarui token sebelum terhubung ke repositori.
- (Opsional) Konfigurasi default untuk perintah gcloud.
Peran yang diperlukan
Untuk mendapatkan izin yang Anda perlukan untuk mengelola paket, minta administrator untuk memberi Anda peran IAM berikut di repositori:
-
Melihat paket atau file dalam paket:
Pembaca Artifact Registry (
roles/artifactregistry.reader) -
Mendownload atau menginstal paket:
Pembaca Artifact Registry (
roles/artifactregistry.reader) -
Menambahkan paket ke repositori:
Penulis Artifact Registry (
roles/artifactregistry.writer) -
Menghapus paket:
Administrator Repositori Artifact Registry (
roles/artifactregistry.repoAdmin)
Untuk mengetahui informasi selengkapnya tentang pemberian peran, lihat Mengelola akses ke project, folder, dan organisasi.
Anda mungkin juga bisa mendapatkan izin yang diperlukan melalui peran khusus atau peran bawaan lainnya.
Menambahkan paket
Mode repositori: Standar
Untuk menambahkan paket ke repositori:
Maven
Gunakan mvn deploy dan mvn release untuk menambahkan paket ke repositori.
Agar berhasil men-deploy project Maven yang mereferensikan induk, project harus menyertakan penyedia Wagon Artifact Registry dalam file ekstensi inti seperti yang dijelaskan dalam petunjuk autentikasi.
Gunakan mvn deploy:deploy-file untuk mengupload artefak yang dibuat di luar Maven.
Misalnya, perintah contoh ini men-deploy example/external.jar dan file project-nya example/pom.xml ke repositori
us-central1-maven.pkg.dev/my-project/my-repo
mvn deploy:deploy-file \
-Durl=artifactregistry://us-central1-maven.pkg.dev/my-project/my-repo \
-DpomFile=example/pom.xml -Dfile=example/external.jar
Untuk mengonfigurasi integrasi dengan Cloud Build, lihat Mengintegrasikan dengan Cloud Build.
Gradle
Agar berhasil memublikasikan ke repositori, file build.gradle Anda harus menyertakan
bagian publikasi yang menentukan file yang akan diupload.
Gunakan perintah gradle publish untuk mengupload paket ke repositori.
Melihat paket dan versi
Mode repositori: standar, jarak jauh
To view packages and package versions using the Google Cloud console
or gcloud:
Console
Open the Repositories page in the Google Cloud console.
In the repository list, click the appropriate repository.
The Packages page lists the packages in the repository.
Click a package to view versions of the package.
gcloud
To list packages in a repository, run the following command:
gcloud artifacts packages list [--repository=REPOSITORY] [--location=LOCATION]
Replace the following:
REPOSITORYis the name of the repository. If you configured a default repository, you can omit this flag to use the default.-
LOCATIONis the regional or multi-regional location of the repository. If you configured a default location, then you can omit this flag to use the default.
To view versions of a package, run the following command:
gcloud artifacts versions list --package=PACKAGE \
[--repository=REPOSITORY] [--location=LOCATION]
Replace the following:
PACKAGEis the ID of the package or fully qualified identifier for the package.REPOSITORYis the name of the repository. If you configured a default repository, then you can omit this flag to use the default.-
LOCATIONis the regional or multi-regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.
Untuk repositori jarak jauh, daftar yang ditampilkan harus menyertakan semua dependensi langsung dan transitif.
Membuat daftar file
Mode repositori: standar, jarak jauh
Anda dapat membuat daftar file di repositori, file di semua versi paket tertentu, atau file di versi paket tertentu.
Untuk semua perintah berikut, Anda dapat menetapkan jumlah maksimum file yang akan ditampilkan dengan menambahkan flag --limit ke perintah.
Untuk membuat daftar semua file di project, repositori, dan lokasi saat nilai default dikonfigurasi:
gcloud artifacts files list
Untuk membuat daftar file di project, repositori, dan lokasi tertentu, jalankan perintah:
gcloud artifacts files list \
--project=PROJECT \
--repository=REPOSITORY \
--location=LOCATION
Untuk membuat daftar file untuk semua versi paket tertentu:
gcloud artifacts files list \
--project=PROJECT \
--repository=REPOSITORY \
--location=LOCATION \
--package=PACKAGE
Untuk membuat daftar file untuk versi paket tertentu:
gcloud artifacts files list \
--project=PROJECT \
--repository=REPOSITORY \
--location=LOCATION \
--package=PACKAGE \
--version=VERSION
Ganti nilai berikut:
LOCATION: lokasi regional atau multi-regional dari repositori.PROJECT: your Google Cloud project ID. Jika project ID Anda berisi titik dua (:), lihat Project dengan cakupan domain.REPOSITORY: nama repositori tempat penyimpanan image.PACKAGE: nama paket.VERSION: versi paket.
Contoh
Pertimbangkan informasi paket berikut:
- Project:
my-project - Repositori:
my-repo - Lokasi repositori:
us-west1 - Paket:
my-app
Perintah berikut mencantumkan semua file di repositori my-repo di
lokasi us-west1 dalam project default:
gcloud artifacts files list \
--location=us-west1 \
--repository=my-repo
1.0.
gcloud artifacts files list \
--project=my-project \
--location=us-west1 \
--repository=my-repo \
--package=my-app \
--version=1.0
Mendownload paket
Mode repositori: standar, jarak jauh, virtual
Untuk mendownload artefak sebagai bagian dari build, Anda mendeklarasikan artefak sebagai dependensi.
Maven
Deklarasikan paket yang ingin Anda download dalam file
pom.xmlproject. Contoh berikut mendeklarasikan paket versi 1.0artifactsebagai dependensi.<dependencies> <dependency> <groupId>group</groupId> <artifactId>artifact</artifactId> <version>1.0</version> </dependency> </dependencies>Untuk mempelajari dependensi Maven lebih lanjut, lihat pengantar Maven tentang dependensi dan referensi dependensi.
Buat project Java.
mvn compile
Gradle
Deklarasikan paket yang ingin Anda download dalam file
build.gradleproject. Contoh berikut mendeklarasikan paket versi 1.0artifactsebagai dependensi kompilasi eksternal.Untuk mempelajari dependensi Gradle lebih lanjut, lihat dokumentasi Gradle.
dependencies { compile group: 'group', name: 'artifact', version: '1.0' }Buat project Java.
gradle build
Untuk repositori standar, Anda mendownload paket langsung dari repositori.
Untuk repositori jarak jauh, Anda mendownload salinan paket yang di-cache dan dependensinya. Jika salinan yang di-cache tidak ada, repositori jarak jauh akan mendownload paket dari sumber upstream dan meng-cache-nya sebelum menayangkannya kepada Anda. Anda dapat memverifikasi bahwa repositori jarak jauh mengambil paket dari sumber upstream dengan melihat daftar paket di repositori.
Untuk repositori virtual, Artifact Registry menelusuri repositori upstream untuk paket yang diminta.
- Repositori jarak jauh upstream akan mendownload dan meng-cache paket yang diminta jika salinan yang di-cache tidak ada. Repositori virtual hanya menayangkan paket yang diminta, bukan menyimpannya.
- Jika Anda meminta versi yang tersedia di lebih dari satu repositori upstream, Artifact Registry akan memilih repositori upstream yang akan digunakan berdasarkan setelan prioritas yang dikonfigurasi untuk repositori virtual.
Misalnya, pertimbangkan repositori virtual dengan setelan prioritas berikut untuk repositori upstream:
main-repo: Prioritas ditetapkan ke100secondary-repo1: Prioritas ditetapkan ke80.secondary-repo2: Prioritas ditetapkan ke80.test-repo: Prioritas ditetapkan ke20.
main-repo memiliki nilai prioritas tertinggi, sehingga repositori virtual selalu menelusurinya terlebih dahulu.
secondary-repo1 dan secondary-repo2 memiliki prioritas yang ditetapkan ke 80. Jika paket yang diminta tidak tersedia di main-repo, Artifact Registry akan menelusuri repositori ini berikutnya. Karena keduanya memiliki nilai prioritas yang sama, Artifact Registry dapat memilih untuk menayangkan paket dari salah satu repositori jika versi tersebut tersedia di keduanya.
test-repo memiliki nilai prioritas terendah dan akan menayangkan artefak yang disimpan jika tidak ada repositori upstream lain yang memilikinya.
Menghapus paket dan versi
Mode repositori: standar, jarak jauh
Anda dapat menghapus paket dan semua versinya, atau menghapus versi tertentu.
- Setelah menghapus paket, Anda tidak dapat mengurungkan tindakan tersebut.
- Untuk repositori jarak jauh, hanya salinan paket yang di-cache yang dihapus. Sumber upstream tidak terpengaruh. Jika Anda menghapus paket yang di-cache, Artifact Registry akan mendownload dan meng-cache-nya lagi saat repositori menerima permintaan untuk versi paket yang sama.
Before you delete a package or package version, verify that any you have communicated or addressed any important dependencies on it.
To delete a package:
Console
Open the Repositories page in the Google Cloud console.
In the repository list, click the appropriate repository.
The Packages page lists the packages in the repository.
Select the package that you want to delete.
Click DELETE.
In the confirmation dialog box, click DELETE.
gcloud
Run the following command:
gcloud artifacts packages delete PACKAGE \
[--repository=REPOSITORY] [--location=LOCATION] [--async]
Replace the following:
PACKAGEis the name of the package in the repository.REPOSITORYis the name of the repository. If you configured a default repository, then you can omit this flag to use the default.-
LOCATIONis the regional or multi-regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.
The --async flag causes the command to return immediately,
without waiting for the operation in progress to complete.
To delete versions of a package:
Console
Open the Repositories page in the Google Cloud console.
In the repository list, click the appropriate repository.
The Packages page lists the packages in the repository.
Click a package to view versions of that package.
Select versions that you want to delete.
Click DELETE.
In the confirmation dialog box, click DELETE.
gcloud
Run the following command:
gcloud artifacts versions delete VERSION \
--package=PACKAGE \
[--repository=REPOSITORY] [--location=LOCATION] \
[--async]
Replace the following:
VERSIONis the name of the version to delete.PACKAGEis the name of the package in the repository.REPOSITORYis the name of the repository. If you configured a default repository, then you can omit this flag to use the default.-
LOCATIONis the regional or multi-regional location of the repository. Use this flag to view repositories in a specific location. If you configured a default location, then you can omit this flag to use the default.
The --async flag causes the command to return immediately,
without waiting for the operation in progress to complete.
Langkah berikutnya
- Pelajari cara mengelola paket Node.js
- Pelajari cara mengelola paket Python
- Pelajari cara mengelola image container
- Mendownload file individual dalam paket