자바 패키지 관리

이 페이지에서는 Java 패키지를 추가, 보기, 삭제하는 방법을 설명합니다.

Scala 및 자바의 빌드 도구로 Maven 또는 Gradle을 사용하는 대신 sbt를 사용하려면 커뮤니티에서 만든 sbt 플러그인을 사용할 수 있습니다. 이 문서에서는 Scala 클라이언트의 구성 또는 사용을 설명하지 않습니다.

시작하기 전에

  1. 대상 저장소가 없으면 새 저장소를 만듭니다.
  2. 저장소에 대해 필요한 권한이 있는지 확인합니다.
  3. 인증을 구성했는지 확인합니다. 액세스 토큰을 사용하는 경우 저장소에 연결하기 전에 토큰을 새로고침해야 합니다.
  4. (선택사항) gcloud 명령어의 기본값을 구성합니다.

필요한 역할

패키지를 관리하는 데 필요한 권한을 얻으려면 관리자에게 저장소에 대한 다음 IAM 역할을 부여해 달라고 요청하세요.

역할 부여에 대한 자세한 내용은 액세스 관리를 참조하세요.

커스텀 역할이나 다른 사전 정의된 역할을 통해 필요한 권한을 얻을 수도 있습니다.

패키지 추가

저장소 모드: 표준

저장소에 패키지를 추가하려면 다음 안내를 따르세요.

Maven

mvn deploymvn release를 사용하여 저장소에 패키지를 추가합니다.

상위 요소를 참조하는 Maven 프로젝트를 성공적으로 배포하려면 인증 안내에 설명된 대로 프로젝트의 핵심 확장 프로그램 파일에 Artifact Registry Wagon 공급자가 포함되어 있어야 합니다.

mvn deploy:deploy-file을 사용하여 Maven 외부에서 빌드된 아티팩트를 업로드합니다.

예를 들어 이 예시 명령어는 example/external.jar 및 프로젝트 파일 example/pom.xmlus-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

Cloud Build와의 통합을 구성하려면 Cloud Build와 통합을 참조하세요.

Gradle

저장소에 성공적으로 게시하려면 build.gradle 파일에 업로드할 파일을 정의하는 게시 섹션이 있어야 합니다.

gradle publish 명령어를 사용하여 패키지를 저장소에 업로드합니다.

패키지 및 버전 보기

저장소 모드: 표준, 원격

To view packages and package versions using the Google Cloud console or gcloud:

Console

  1. Open the Repositories page in the Google Cloud console.

    저장소 페이지 열기

  2. In the repository list, click the appropriate repository.

    The Packages page lists the packages in the repository.

  3. 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]

Where

  • REPOSITORY is the name of the repository. If you configured a default repository, you can omit this flag to use the default.
  • LOCATION is a regional or multi-regional location. Use this flag to view repositories in a specific location. If you configured a default location, 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]

Where

  • 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, you can omit this flag to use the default.
  • LOCATION is a regional or multi-regional location. Use this flag to view repositories in a specific location. If you configured a default location, you can omit this flag to use the default.

원격 저장소의 경우 반환된 목록에 모든 직접 및 임시 종속 항목이 포함되어야 합니다.

파일 나열

저장소 모드: 표준, 원격

저장소의 파일, 지정된 패키지의 모든 버전 파일, 패키지의 특정 버전 파일을 나열할 수 있습니다.

다음 모든 명령어에 대해 --limit 플래그를 명령어에 추가하여 반환할 최대 파일 수를 설정할 수 있습니다.

기본값이 구성된 경우 기본 프로젝트, 저장소, 위치의 모든 파일을 나열하려면 다음 명령어를 실행합니다.

gcloud artifacts files list

지정된 프로젝트, 저장소, 위치의 파일을 나열하려면 다음을 실행합니다.

gcloud artifacts files list \
    --project=PROJECT \
    --repository=REPOSITORY \
    --location=LOCATION

특정 패키지의 모든 버전에 대한 파일을 나열하려면 다음을 실행합니다.

gcloud artifacts files list \
    --project=PROJECT \
    --repository=REPOSITORY \
    --location=LOCATION \
    --package=PACKAGE

특정 패키지 버전의 파일을 나열하려면 다음을 실행합니다.

gcloud artifacts files list \
    --project=PROJECT \
    --repository=REPOSITORY \
    --location=LOCATION \
    --package=PACKAGE \
    --version=VERSION

다음 값을 바꿉니다.

  • LOCATION: 저장소의 리전 또는 멀티 리전 위치입니다.
  • PROJECT: Google Cloud 프로젝트 ID 프로젝트 ID에 콜론(:)이 포함되어 있으면 도메인 범위 프로젝트를 참조하세요.
  • REPOSITORY: 이미지가 저장된 저장소의 이름입니다.
  • PACKAGE: 패키지의 이름입니다.
  • VERSION: 패키지의 버전입니다.

예시

다음 패키지 정보를 고려하세요.

  • 프로젝트: my-project
  • 저장소: my-repo
  • 저장소 위치: us-central1
  • 패키지: my-app

다음 명령어는 기본 프로젝트 내의 us-central1 위치에 있는 my-repo 저장소의 모든 파일을 나열합니다.

gcloud artifacts files list \
    --location=us-central1 \
    --repository=my-repo
다음 명령어는 패키지의 1.0 버전 파일을 나열합니다.

gcloud artifacts files list \
    --project=my-project \
    --location=us-central1 \
    --repository=my-repo \
    --package=my-app \
    --version=1.0

패키지 다운로드

저장소 모드: 표준, 원격, 가상

아티팩트를 빌드의 일부로 다운로드하려면 아티팩트를 종속 항목으로 선언합니다.

Maven

  1. 프로젝트 pom.xml 파일에서 다운로드할 패키지를 선언합니다. 다음 예시에서는 artifact 패키지 버전 1.0을 종속 항목으로 선언합니다.

    <dependencies>
        <dependency>
            <groupId>group</groupId>
            <artifactId>artifact</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
    

    Maven 종속 항목에 대한 자세한 내용은 Maven 종속 항목 소개종속 항목 참조를 확인하세요.

  2. Java 프로젝트를 빌드합니다.

    mvn compile
    

Gradle

  1. 프로젝트 build.gradle 파일에서 다운로드할 패키지를 선언합니다. 다음 예시에서는 artifact 패키지의 버전 1.0을 외부 컴파일 종속 항목으로 선언합니다.

    Gradle 종속 항목에 대한 자세한 내용은 Gradle 문서를 참조하세요.

    dependencies {
        compile group: 'group', name: 'artifact', version: '1.0'
    }
    
  2. Java 프로젝트를 빌드합니다.

    gradle build
    

표준 저장소의 경우 저장소에서 직접 패키지를 다운로드합니다.

원격 저장소의 경우 패키지와 해당 종속 항목의 캐시된 복사본을 다운로드합니다. 캐시된 복사본이 없으면 원격 저장소가 업스트림 소스에서 패키지를 다운로드하고 캐시한 후에 개발자에게 제공합니다. 저장소의 패키지 목록을 확인하여 원격 저장소가 업스트림 소스에서 패키지를 검색했는지 확인할 수 있습니다.

가상 저장소의 경우 Artifact Registry에서 요청된 패키지의 업스트림 저장소를 검색합니다.

  • 캐시된 복사본이 없으면 업스트림 원격 저장소에서 요청된 패키지를 다운로드하고 캐시합니다. 가상 저장소는 요청된 패키지만 제공하고 저장하지 않습니다.
  • 업스트림 저장소 2개 이상에서 사용할 수 있는 버전을 요청하면 Artifact Registry에서 가상 저장소에 구성된 우선순위 설정에 따라 사용할 업스트림 저장소를 선택합니다.

예를 들어 업스트림 저장소에 대해 다음 우선순위 설정을 사용하는 가상 저장소가 있다고 가정해보세요.

  • main-repo: 우선순위가 100으로 설정됩니다.
  • secondary-repo1: 우선순위가 80으로 설정됩니다.
  • secondary-repo2: 우선순위가 80으로 설정됩니다.
  • test-repo: 우선순위가 20으로 설정됩니다.

main-repo의 우선순위 값이 가장 높으므로 가상 저장소가 항상 이를 먼저 검색합니다.

secondary-repo1secondary-repo2는 우선순위가 모두 80으로 설정됩니다. 요청된 패키지가 main-repo에 없으면 Artifact Registry가 그 다음으로 이 저장소를 검색합니다. 두 항목 모두 우선순위 값이 동일하므로, 두 항목 모두 버전을 사용할 수 있으면 Artifact Registry가 어느 저장소에서든 패키지를 제공하도록 선택할 수 있습니다.

test-repo는 우선순위 값이 가장 낮고 다른 업스트림 저장소에 없을 때만 저장된 아티팩트를 제공합니다.

패키지 및 버전 삭제

저장소 모드: 표준, 원격

패키지 및 모든 해당 버전을 삭제하거나 특정 버전을 삭제할 수 있습니다.

  • 패키지를 삭제하면 작업을 실행취소할 수 없습니다.
  • 원격 저장소의 경우 패키지의 캐시된 복사본만 삭제됩니다. 업스트림 소스는 영향을 받지 않습니다. 캐시된 패키지를 삭제하면 다음에 저장소가 동일한 패키지 버전에 대한 요청을 받을 때 Artifact Registry가 해당 패키지를 다운로드하고 다시 캐시합니다.

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

  1. Open the Repositories page in the Google Cloud console.

    저장소 페이지 열기

  2. In the repository list, click the appropriate repository.

    The Packages page lists the packages in the repository.

  3. Select the package that you want to delete.

  4. Click DELETE.

  5. In the confirmation dialog box, click DELETE.

gcloud

Run the following command:

gcloud artifacts packages delete PACKAGE \
    [--repository=REPOSITORY] [--location=LOCATION] [--async]

Where

  • PACKAGE is the name of the package in the repository.
  • REPOSITORY is the name of the repository. If you configured a default repository, you can omit this flag to use the default.
  • LOCATION is a regional or multi-regional location. Use this flag to view repositories in a specific location. If you configured a default location, you can omit this flag to use the default.
  • --async Return immediately, without waiting for the operation in progress to complete.

To delete versions of a package:

Console

  1. Open the Repositories page in the Google Cloud console.

    저장소 페이지 열기

  2. In the repository list, click the appropriate repository.

    The Packages page lists the packages in the repository.

  3. Click a package to view versions of that package.

  4. Select versions that you want to delete.

  5. Click DELETE.

  6. In the confirmation dialog box, click DELETE.

gcloud

Run the following command:

gcloud artifacts versions delete VERSION \
    --package=PACKAGE \
    [--repository=REPOSITORY] [--location=LOCATION] \
    [--async]

Where

  • PACKAGE is the name of the package in the repository.
  • REPOSITORY is the name of the repository. If you configured a default repository, you can omit this flag to use the default.
  • LOCATION is a regional or multi-regional location. Use this flag to view repositories in a specific location. If you configured a default location, you can omit this flag to use the default.
  • --async returns immediately, without waiting for the operation in progress to complete.

다음 단계