GoogleCloudPlatform / artifact-registry-maven-tools

Apache License 2.0
24 stars 22 forks source link

Gradle: credentials are not updated between invocations since daemon stays alive #39

Closed asodja closed 3 years ago

asodja commented 3 years ago

I noticed on Jenkins when calling two gradle commands one after another that credentials were not updated in case like:

// Here credentials are fetched with read-only access for build
sh "./gradlew build"
// Here we set service account with write permissions, but credentials are not updated, so publish fails
withCredentials([file(credentialsId: env.GCP_SERVICE_ACCOUNT_FILE, variable: 'GOOGLE_APPLICATION_CREDENTIALS')]) {
     sh "./gradlew publish"
}

I noticed the same thing locally:

  1. I ran ./gradlew build with account that did not have any gcp artifact permissions, build failed
  2. Naturally I did gcloud auth login with account with permissions
  3. I ran ./gradlew build build failed again...
  4. After 15 minutes of debugging I tried ./gradlew --stop and after that ./gradlew build worked

This behaviour is most likely due to Gradle daemon. I am not sure if this is a feature or a bug, but it's annoying to debug and maybe needs a fix.

Tested with: "com.google.cloud.artifactregistry.gradle-plugin" version "2.1.1"

loosebazooka commented 3 years ago

@asodja what version of gradle are you using?

From my testing, any changed environment is picked up by the daemon.

yihanzhen commented 3 years ago

Closing the issue due to inactivity, but feel free to let us know if you run into this again.