利用 Google Artifact Repository 构建maven jar 存储仓库

参考了google 官方文档

https://cloud.google.com/artifact-registry/docs/java/store-java#gcloud_1

首先 enable GAR api

bash 复制代码
gcloud services enable artifactregistry.googleapis.com
gcloud services list | grep -i artifact
artifactregistry.googleapis.com      Artifact Registry API

其次创建1个maven 仓库

gcloud artifacts repositories create java-repo --repository-format=maven --location=eurepo-west2 --description="Java package repository"

bash 复制代码
> gcloud artifacts repositories create java-repo --repository-format=maven --location=europe-west2 --description="Java package repository"
Create request issued for: [java-repo]
Waiting for operation [projects/jason-hsbc/locations/europe-west2/operations/a171307f-627c-471f-bd5d-0ad647237b5e] to complete...done.                                                               
Created repository [java-repo].

用如下命令来list 已有的仓库

bash 复制代码
> gcloud artifacts repositories list
Listing items under project jason-hsbc, across all locations.

                                                                                                                      ARTIFACT_REGISTRY
REPOSITORY      FORMAT  MODE                 DESCRIPTION                                                                                 LOCATION      LABELS                          ENCRYPTION          CREATE_TIME          UPDATE_TIME          SIZE (MB)
gcf-artifacts   DOCKER  STANDARD_REPOSITORY  This repository is created and used by Cloud Functions for storing function docker images.  europe-west2  goog-managed-by=cloudfunctions  Google-managed key  2023-11-05T04:54:28  2023-11-05T04:56:07  744.026
java-repo       MAVEN   STANDARD_REPOSITORY  Java package repository                                                                     europe-west2                                  Google-managed key  2023-11-11T03:21:31  2023-11-11T03:21:31  0
my-docker-repo  DOCKER  STANDARD_REPOSITORY                                                                                              europe-west2                                  Google-managed key  2023-09-09T17:01:40  2023-09-09T17:01:40  0

打印maven仓库设置,

bash 复制代码
> gcloud artifacts print-settings mvn --location=europe-west2 --repository=java-repo
<!-- Insert following snippet into your pom.xml -->

<project>
  <distributionManagement>
    <snapshotRepository>
      <id>artifact-registry</id>
      <url>artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo</url>
    </snapshotRepository>
    <repository>
      <id>artifact-registry</id>
      <url>artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo</url>
    </repository>
  </distributionManagement>

  <repositories>
    <repository>
      <id>artifact-registry</id>
      <url>artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo</url>
      <releases>z
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>

  <build>
    <extensions>
      <extension>
        <groupId>com.google.cloud.artifactregistry</groupId>
        <artifactId>artifactregistry-maven-wagon</artifactId>
        <version>2.2.0</version>
      </extension>
    </extensions>
  </build>
</project>

把上面的内容insert 到maven 项目的pom.xml中

执行mvn deploy 部署jar 到GAR

mvn deploy -Dhttps.proxyHost=10.0.1.223 -Dhttps.proxyPort=7890 -Dhttp.proxyHost=10.0.1.223 -Dhttp.proxyPort=7890

bash 复制代码
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] 
[INFO] --- maven-jar-plugin:3.2.0:jar (default-jar) @ helloservice ---
[INFO] Building jar: /home/gateman/Projects/spring-boot-for-cloud-run/target/helloservice-0.0.1-SNAPSHOT.jar
[INFO] 
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ helloservice ---
[INFO] Installing /home/gateman/Projects/spring-boot-for-cloud-run/target/helloservice-0.0.1-SNAPSHOT.jar to /home/gateman/.m2/repository/com/home/cloudrun/helloservice/0.0.1-SNAPSHOT/helloservice-0.0.1-SNAPSHOT.jar
[INFO] Installing /home/gateman/Projects/spring-boot-for-cloud-run/pom.xml to /home/gateman/.m2/repository/com/home/cloudrun/helloservice/0.0.1-SNAPSHOT/helloservice-0.0.1-SNAPSHOT.pom
[INFO] 
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ helloservice ---
Downloading from artifact-registry: artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo/com/home/cloudrun//helloservice/0.0.1-SNAPSHOT/maven-metadata.xml
[INFO] Initializing Credentials...
[INFO] Using Application Default Credentials.
[INFO] Refreshing Credentials...
Downloaded from artifact-registry: artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo/com/home/cloudrun//helloservice/0.0.1-SNAPSHOT/maven-metadata.xml (780 B at 665 B/s)
Uploading to artifact-registry: artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo/com/home/cloudrun//helloservice/0.0.1-SNAPSHOT/helloservice-0.0.1-20231110.203247-2.jar
Uploaded to artifact-registry: artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo/com/home/cloudrun//helloservice/0.0.1-SNAPSHOT/helloservice-0.0.1-20231110.203247-2.jar (4.1 kB at 3.9 kB/s)
Uploading to artifact-registry: artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo/com/home/cloudrun//helloservice/0.0.1-SNAPSHOT/helloservice-0.0.1-20231110.203247-2.pom
Uploaded to artifact-registry: artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo/com/home/cloudrun//helloservice/0.0.1-SNAPSHOT/helloservice-0.0.1-20231110.203247-2.pom (3.1 kB at 3.2 kB/s)
Downloading from artifact-registry: artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo/com/home/cloudrun//helloservice/maven-metadata.xml
Downloaded from artifact-registry: artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo/com/home/cloudrun//helloservice/maven-metadata.xml (290 B at 531 B/s)
Uploading to artifact-registry: artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo/com/home/cloudrun//helloservice/0.0.1-SNAPSHOT/maven-metadata.xml
Uploaded to artifact-registry: artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo/com/home/cloudrun//helloservice/0.0.1-SNAPSHOT/maven-metadata.xml (780 B at 944 B/s)
Uploading to artifact-registry: artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo/com/home/cloudrun//helloservice/maven-metadata.xml
Uploaded to artifact-registry: artifactregistry://europe-west2-maven.pkg.dev/jason-hsbc/java-repo/com/home/cloudrun//helloservice/maven-metadata.xml (290 B at 451 B/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  12.191 s
[INFO] Finished at: 2023-11-10T20:32:51Z
[INFO] ------------------------------------------------------------------------

上传成功

bash 复制代码
gateman@instance-2:~/Projects/spring-boot-for-cloud-run$ gcloud artifacts packages list --repository=java-repo --location=europe-west2
Listing items under project jason-hsbc, location europe-west2, repository java-repo.

PACKAGE                         CREATE_TIME          UPDATE_TIME
com.home.cloudrun:helloservice  2023-11-10T19:56:17  2023-11-10T20:32:48
相关推荐
2202_754421547 分钟前
生成MPSOC以及ZYNQ的启动文件BOOT.BIN的小软件
java·linux·开发语言
蓝染-惣右介9 分钟前
【MyBatisPlus·最新教程】包含多个改造案例,常用注解、条件构造器、代码生成、静态工具、类型处理器、分页插件、自动填充字段
java·数据库·tomcat·mybatis
小林想被监督学习10 分钟前
idea怎么打开两个窗口,运行两个项目
java·ide·intellij-idea
HoneyMoose12 分钟前
IDEA 2024.3 版本更新主要功能介绍
java·ide·intellij-idea
我只会发热14 分钟前
Java SE 与 Java EE:基础与进阶的探索之旅
java·开发语言·java-ee
是老余15 分钟前
本地可运行,jar包运行错误【解决实例】:通过IDEA的maven package打包多模块项目
java·maven·intellij-idea·jar
crazy_wsp15 分钟前
IDEA怎么定位java类所用maven依赖版本及引用位置
java·maven·intellij-idea
.Ayang18 分钟前
tomcat 后台部署 war 包 getshell
java·计算机网络·安全·web安全·网络安全·tomcat·网络攻击模型
bjzhang7523 分钟前
SpringBoot开发——Maven多模块工程最佳实践及详细示例
spring boot·maven·maven多模块工程
一直学习永不止步23 分钟前
LeetCode题练习与总结:最长回文串--409
java·数据结构·算法·leetcode·字符串·贪心·哈希表