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, tersedia plugin sbt yang dibuat komunitas. Dokumentasi ini tidak menjelaskan konfigurasi atau penggunaan klien Scala.
Sebelum memulai
- Jika repositori target tidak ada, buat repositori baru.
- Verifikasi bahwa Anda memiliki izin yang diperlukan untuk repositori.
- Pastikan Anda telah mengonfigurasi autentikasi. Jika Anda menggunakan token akses, pastikan Anda memuat ulang token sebelum terhubung ke repositori.
- (Opsional) Konfigurasi default untuk perintah gcloud.
Peran yang diperlukan
Untuk mendapatkan izin yang diperlukan untuk mengelola paket, minta administrator Anda 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
) -
Tambahkan paket ke repositori:
Artifact Registry Writer (
roles/artifactregistry.writer
) -
Menghapus paket:
Administrator Repositori Artifact Registry (
roles/artifactregistry.repoAdmin
)
Untuk mengetahui informasi selengkapnya tentang cara memberikan peran, lihat Mengelola akses ke project, folder, dan organisasi.
Anda mungkin juga bisa mendapatkan izin yang diperlukan melalui peran kustom atau peran yang telah ditentukan 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
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 dipublikasikan ke repositori, file build.gradle
Anda harus menyertakan bagian publications yang menentukan file untuk 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:
REPOSITORY
is the name of the repository. If you configured a default repository, you can omit this flag to use the default.-
LOCATION
is 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:
PACKAGE
is the ID of the package or fully qualified identifier for the package.REPOSITORY
is the name of the repository. If you configured a default repository, then you can omit this flag to use the default.-
LOCATION
is 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.
Mencantumkan file
Mode repositori: standar, jarak jauh
Anda dapat mencantumkan file dalam repositori, file dalam semua versi paket yang ditentukan, atau file dalam versi tertentu dari suatu paket.
Untuk semua perintah berikut, Anda dapat menetapkan jumlah maksimum file yang akan ditampilkan
dengan menambahkan tanda --limit
ke perintah.
Untuk mencantumkan semua file dalam project, repositori, dan lokasi default saat nilai default dikonfigurasi:
gcloud artifacts files list
Untuk mencantumkan file dalam project, repositori, dan lokasi tertentu, jalankan perintah:
gcloud artifacts files list \
--project=PROJECT \
--repository=REPOSITORY \
--location=LOCATION
Untuk mencantumkan file untuk semua versi paket tertentu:
gcloud artifacts files list \
--project=PROJECT \
--repository=REPOSITORY \
--location=LOCATION \
--package=PACKAGE
Untuk mencantumkan 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 repositori.PROJECT
: Google Cloud Project ID Anda. Jika project ID Anda berisi titik dua (:
), lihat Project cakupan domain.REPOSITORY
: nama repositori tempat penyimpanan image.PACKAGE
: nama paket.VERSION
: versi paket.
Contoh
Pertimbangkan informasi paket berikut:
- Project:
my-project
- Repository:
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.xml
project. Contoh berikut mendeklarasikan versi 1.0 paketartifact
sebagai dependensi.<dependencies> <dependency> <groupId>group</groupId> <artifactId>artifact</artifactId> <version>1.0</version> </dependency> </dependencies>
Untuk mempelajari lebih lanjut dependensi Maven, lihat pengantar dependensi dan referensi dependensi Maven.
Bangun project Java.
mvn compile
Gradle
Deklarasikan paket yang ingin Anda download dalam file
build.gradle
project. Contoh berikut mendeklarasikan paketartifact
versi 1.0 sebagai dependensi kompilasi eksternal.Untuk mempelajari lebih lanjut dependensi Gradle, lihat dokumentasi Gradle.
dependencies { compile group: 'group', name: 'artifact', version: '1.0' }
Bangun 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, tidak 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 ke100
secondary-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 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 men-cache-nya lagi saat repositori menerima permintaan untuk versi paket yang sama pada waktu berikutnya.
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:
PACKAGE
is the name of the package in the repository.REPOSITORY
is the name of the repository. If you configured a default repository, then you can omit this flag to use the default.-
LOCATION
is 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:
VERSION
is the name of the version to delete.PACKAGE
is the name of the package in the repository.REPOSITORY
is the name of the repository. If you configured a default repository, then you can omit this flag to use the default.-
LOCATION
is 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 satu per satu dalam paket