我在我的 gradle 專案中包含了插件“com.google.cloud.artifactregistry.gradle-plugin”。
plugins {
......
id "com.google.cloud.artifactregistry.gradle-plugin" version "2.1.1"
}
在拉動程序中我總是收到一條錯誤訊息:
Failed to apply plugin 'com.google.cloud.artifactregistry.gradle-plugin'.
Failed to get access token from gcloud or Application Default Credentials
有誰知道為什么?我在這篇文章https://github.com/GoogleCloudPlatform/artifact-registry-maven-tools/issues/34 中看到了它。我首先需要有一個 GCP 帳戶。我下載了 GCP SDK,并登錄到我的帳戶,但仍然收到相同的訊息。誰能提供更具體的解決方案?謝謝。
uj5u.com熱心網友回復:
我沒試過這個
看看設定身份驗證級別在谷歌的神器注冊檔案。
希望您可以使用憑證助手
應用程式默認憑據是一項非常有用的 Google 平臺功能,可簡化獲取憑據的程序。代碼(不是gcloud)運行:
- 可以通過環境變數設定 (
GOOGLE_APPLICATION_CREDENTIALS)將 off-GCP(本地或例如 GitHub|GitLab)配置為使用憑據 - on-GCP(例如 Compute Engine)自動獲取憑據(例如元資料服務)。
我懷疑 (!) Maven|Gradle 插件GOOGLE_APPLICATION_CREDENTIALS以這種方式尋找(使用服務帳戶)向 Google 驗證您的腳本。
更新:示例
BILLING=[[YOUR-BILLING]]
PROJECT=[[YOUR-PROJECT]]
REPO=[[YOUR-REPO]] # E.g. repo
LOCATION=[[YOUR-LOCATION]] # E.g. us-west2
gcloud projects create ${PROJECT}
gcloud beta billing projects link ${PROJECT} \
--billing-account=${BILLING}
# Enable Artifact Registry
gcloud services enable artifactregistry.googleapis.com \
--project=${PROJECT}
# Create Maven repository
gcloud artifacts repositories create ${REPO} \
--location=${LOCATION} \
--repository-format=maven \
--project=${PROJECT}
# Create Service Account to be used by gradle
ACCOUNT="gradle"
EMAIL=${ACCOUNT}@${PROJECT}.iam.gserviceaccount.com
gcloud iam service-accounts create ${ACCOUNT} \
--project=${PROJECT}
gcloud iam service-accounts keys create ${PWD}/${ACCOUNT}.json \
--iam-account=${EMAIL}
# Export the Service Account key as Application Default Creds
export GOOGLE_APPLICATION_CREDENTIALS=${PWD}/${ACCOUNT}.json
# Grant the Service Account permissions to Artifact Registry
gcloud projects add-iam-policy-binding ${PROJECT} \
--member=serviceAccount:${EMAIL} \
--role=roles/artifactregistry.admin
# Get the Gradle settings
# You'll need to manually merge these
gcloud artifacts print-settings gradle \
--project=${PROJECT} \
--repository=${REPO} \
--location=${LOCATION}
我./gradlew init用來創建一個基本的 Java 應用程式。然后我調整了build.grade. 我根本沒有使用過 Gradle,如果這是不正確的,我深表歉意:
plugins {
id 'java'
id 'application'
id "maven-publish"
id "com.google.cloud.artifactregistry.gradle-plugin" version "2.1.1"
}
publishing {
publications {
maven(MavenPublication) {
groupId = "com.dazwilkin.test"
artifactId = "application"
version = "0.1"
from components.java
}
}
repositories {
maven {
url "artifactregistry://${LOCATION}-maven.pkg.dev/${PROJECT}/${REPO}"
}
}
}
repositories {
jcenter()
maven {
url "artifactregistry://${LOCATION}-maven.pkg.dev/${PROJECT}/${REPO}"
}
}
dependencies {
implementation 'com.google.guava:guava:28.0-jre'
testImplementation 'junit:junit:4.12'
}
application {
mainClassName = 'com.dazwilkin.test.App'
}
然后:
./gradlew publish
BUILD SUCCESSFUL in 3s
5 actionable tasks: 3 executed, 2 up-to-date
和:
gcloud artifacts packages list \
--repository=${REPO} \
--location=${LOCATION} \
--project=${PROJECT}
產量:
Listing items under project [[PROJECT]], location [[LOCATION]], repository [[REPO]].
PACKAGE: com.dazwilkin.test:application
CREATE_TIME: 2021-12-09T17:34:19
UPDATE_TIME: 2021-12-09T17:44:20
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/378856.html
上一篇:使用gradleclojurephant插件“加載后找不到命名空間”的clojure專案構建
下一篇:gradle發布project-version-PLAIN.war檔案而不是project-version.war
