GoogleContainerTools / GoogleContainerTools/skaffold

usage of "-SNAPSHOT" dependencies breaks Gradle builds

Open
#9,535 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
15.9k
Forks
1.7k
Avg merge
3d 9h
Merged PRs (30d)
10

Description

### Expected behavior
When I run `skaffold build -p $profile` to execute a Jib build for my Gradle project, which consumes one or more "-SNAPSHOT" dependencies, Skaffold successfully uploads a "source archive" to GCS, downloads and unpacks that archive, and proceeds with the build as configured.

### Actual behavior
With the following profile definition:
```
- name: dev
build:
googleCloudBuild:
projectId: $gcpProjectId
gradleImage: gradle:8.2.1-jdk17-alpine
artifacts:
- image: $destinationContainerRepo
jib:
type: gradle
project: service
```

`skaffold build -p dev` fails like so:
```
Pushing code to gs://my-cloudbuild-bucket/source/source-archive-prefix-.tar.gz
uploading source archive: uploading sources to google storage: Rel: can't make /Users/me/.gradle/caches/modules-2/files-2.1/my.org/my-shared-lib/0.0.1-SNAPSHOT//my-shared-lib-0.0.1-SNAPSHOT.jar relative to .
```

If I add `context: $absolutePathToProjectRoot` to the build artifact in the above profile config, `skaffold build -p dev` fails like so:
```
Fetching storage object: gs://my-cloudbuild-bucket/source/source-archive-prefix-.tar.gz#$epochTimestampMicros
Copying gs://my-cloudbuild-bucket/source/source-archive-prefix-.tar.gz#$epochTimestampMicros...
/ [1 files][ 14.2 MiB/ 14.2 MiB]
Operation completed over 1 objects/14.2 MiB.
tar: Removing leading `../../../' from member names
tar: ../../../.gradle/caches/modules-2/files-2.1/my.org/my-shared-lib/0.0.1-SNAPSHOT//my-shared-lib-0.0.1-SNAPSHOT.jar: Member name contains '..'
tar: Exiting with failure status due to previous errors
```

NOTE: the above failure modes occur only when my project is configured to consume a `-SNAPSHOT` version of the relevant dependency (since this prompts Skaffold/Jib to include a copy of the dependency in the sources archive). The build works fine if I change the Gradle dependency config to consume `my-shared-lib:0.0.1` rather than `my-shared-lib:0.0.1-SNAPSHOT`.

I would _suspect_ there is some way to configure Skaffold and/or Jib to work around this (aside from nuclear options such as running builds in the same directory as the Gradle cache or setting `GRADLE_USER_HOME` to force the creation of a brand new cache directory in the build directory)...but I'm not finding it.

Thanks in advance!

### Information
- Skaffold version: `v2.9.0`
- Operating system: `macOS 14.7`
- Installed via: `Google Cloud SDK`
- Contents of skaffold.yaml: see snippet above (I think that should be sufficient here, but I'm happy to share more if it would be helpful...I'll just need to obfuscate the contents, which is a bit tedious)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.