Using a copy of the .ivy2 cache as SBT resolver source
Asked Answered
A

2

6

I'm trying to package a few in-house artifacts for use with SBT. I would just use the libs directory in most cases, but there are multiple projects that share the same artifacts.

I've been trying to use the directory structure that is produced by SBT as a basis for this small repository. It stores the artifacts in .ivy2 like so:

.ivy2/cache/[org-with-dots]/[module]/[artifact]-[version].[ext]

I've copied the stuff i need under cache to it's own folder and then tried the following patterns in SBT to no avail:

resolvers += "cache" at "file:/../ivy-cache"
resolvers += Resolver.file("cache", file("../ivy-cache"))
resolvers += Resolver.file("cache", file("../ivy-cache"))(Resolver.ivyStylePatterns)
resolvers += Resolver.file("cache", file("../ivy-cache"))(Patterns("[organization]/[module]/[artifact]-[revision].[ext]"))

None of these work. The closest was the last one, but organization comes out with slashes instead of dots. The Resolver.ivyStylePatterns used dots in the organization, but expected a folder called ivys to be used.

So I have a two part question:

  1. Should I just be doing something else to capture these locally hosted artifacts? Im not building them, so publish is not desirable.
  2. Is there a way to specify the pattern I want above without doing a string replacement from / to . in the organization component?
Auctioneer answered 5/1, 2016 at 19:36 Comment(4)
If the jars are in the cache, why do you think sbt would go as far as to downloading them once more? They're already cached, aren't they? It's a local cache of the deps you've once requested to pull down.Convince
I'm giving the code to someone who isn't on our intranet, which has it's own artifactory server. So I'm replacing our internal artifact servers with a cached repository for those jars.Auctioneer
It'd be likely easier to just upload the jars to a proper repository manager and let others use it...*properly*.Convince
Obviously that is not an option, else I wouldn't be doing this song and dance. That being said, the tool supports filesystem-borne repositories so my usage is, in fact, proper. It's even in the manual.Auctioneer
A
5

Found the answer, Pattern has an apply overload which takes a boolean parameter for its first argument. When true it uses a Maven style organization string which uses slashes to separate the components, when false it uses Ivy style (dots).

Here's what worked (with SBT 0.3.9):

resolvers += Resolver.file("cache", file("../ivy-cache"))(Patterns(false,"[organization]/[module]/[artifact]-[revision].[ext]"))

PS: if someone provides a better workflow instead, i will accept that over this answer...

Auctioneer answered 6/1, 2016 at 14:2 Comment(0)
A
1

Firstly the ivy cache has a different file system layout, which might explain the problems you're having with pattern matching in sbt

Secondly (and more importantly) the ivy cache is not designed to be used as the definitive copy of files a build depends on. For example a cache might be purged (indeed ivy contains a command that does exactly that).

Related to the following questions:

Aeriell answered 5/1, 2016 at 20:45 Comment(1)
1, yes and I'm trying to match that layout but don't see any direct way to do so, which I find strange. And 2, that's why i copied the resources to another directory that isn't affected by cache functions, like purging.Auctioneer

© 2022 - 2024 — McMap. All rights reserved.