hello! I got a requirement to create dependency bu...
# gradle
d
hello! I got a requirement to create dependency bundle for my project that can be fetched from s3 instead of downloading dependencies from internet (i.e. build happens on containers that won’t have shared maven/gradle cache). I’m trying to create archive as
Copy code
register<Zip>("createS3DependencyBundle") {
        archiveFileName.set("${project.name}-dependencies.zip")
        destinationDirectory.set(file("$buildDir/dist"))

        from(fileTree(File(gradle.gradleHomeDir, "caches/modules-2/files-2.1")))
    }
but no zip archive is created - any ideas?
o
did you depend on the task in any way?
d
i explicitly run it as
gradle createS3DependencyBundle
getting build success but nothing created under
build/dist
o
oh, I know what's up --
gradleHomeDir
!=
gradleUserHomeDir
the former is wherever the gradle binary is stored, the latter is where things are cached
d
ah nice! thanks let me try it
o
I would note that this is pretty unreliable, it would probably be better to resolve all of your configurations and take each of the dependencies' artifact files and store that in the zip
if gradle ever changes their caching format, this will break, but using the artifact files won't
d
mind elaborating on how to
better to resolve all of your configurations and take each of the dependencies' artifact files and store _that_ in the zip
?
tldr i’m migrating our build from maven
so they were just zipping .m2/repository
things get a “little” more complicated on gradle side to do the same thing
o
I suppose it depends on how you're going to use it
if you just plan to unzip it on the container, I would capture at a higher level, i.e. take the entire
caches
folder
d
was planning to unzip it and drop it to that directory
doesn’t caches folder also contain execution stuff?
o
I think they contain caches for the kotlin DSL, but they don't contain output caches (that's all in the
build
directory)
d
I guess I need to filter
*.lock
files?
o
yes, that's probably a good idea
d
I’ll try that out thanks
r
you can treat the S3 bucket as a Maven repository and use ‘maven-publish’ plugin to publish your project as a Jar/Aar to it. https://ryanharter.com/blog/2015/06/18/hosting-a-private-maven-repo-on-amazon-s3/
o
I think that's a fundamentally different question -- this isn't about publishing project output, but sharing the gradle cache among multiple builds https://docs.gradle.org/6.2/release-notes.html#shared-dependency-cache touches on something similar to this, but it's certainly more complicated
r
oh, sorry I understood it in a different context
you can use Gradle Enterprise as remote build cache btw
d
yeah i need to cache dependencies
pushing out artifacts is much simpler
how does remote cache handles the dependencies? i guess they are downloaded locally on build time?
o
build cache is only for project outputs, it still downloads dependencies to my knowledge
d
thats what i thought thnx
o
personally I would host a "close" (same host/LAN) maven mirror, rather than trying to play with storing the gradle cache, but at the same time the gradle cache is certainly faster + contains things other than dependencies
d
well so we do host our artyfactory but for some reason group i’m working with wanted to go with s3 solution anyway
so do the copy of the deps and zip the m2