在 Gradle 中,如何忽略本地 ivy 存储库的缓存?
在我的 Gradle 脚本(版本 0.8)中,我有一个本地 ivy 存储库,我用它来发布库,而且我似乎无法让 Gradle 忽略它的缓存。
我正在访问本地常春藤仓库。基于 Gradle 手册中的建议。这是相关代码(一些变量已重命名)。
dependencies{
// [several remote dependencies]
// ...
compile('myorg:mylib:0.1.0')
}
def ivy_repo = new org.apache.ivy.plugins.resolver.FileSystemResolver()
ivy_repo.name = 'ivy-repo'
ivy_repo.addIvyPattern local_repository + '/ivy/[organisation]/'+
'[module]-ivy-[revision].xml'
ivy_repo.addArtifactPattern local_repository + '/ivy/[organisation]/'+
'[module]-[revision](-[classifier]).[ext]'
ivy_repo.descriptor = 'optional'
ivy_repo.checkmodified = true
repositories{
// [several remote repositories]
// ...
add(ivy_repo)
}
我的问题是,当我运行脚本时,一旦解析了本地库,对构建脚本的后续调用将使用 ~/.gradle/cache/myorg:mylib/,而不是本地 ivy 存储库的位置。 Gradle 手册只有几行提到默认本地存储库不应使用缓存,但我现在找到了实际表明我的存储库是“默认”和本地存储库的方法,因此不应使用缓存。
我尝试设置 ivy_repo.local = true 或使用compile('myorg:mylib:0.1.0'){change = true},但似乎都不起作用。
我不想使用 flatDir 存储库,因为本地库具有我希望我的项目找到的依赖项(并且我现在使用与本地库关联的 ivy 文件来执行此操作,并且似乎 flatDir 存储库会忽略这些类型的文件...或者也许我在那里做错了什么?)
有人知道解决方案吗?或者也许是使用 Gradle 完成任务的更好方法?
In my Gradle script (version 0.8), I have a local ivy repository which I use to publish a library, and I can't seem to get Gradle to ignore its cache.
I'm accessing the local ivy repo. based on the recommendation in the Gradle manual. Here's there relevant code (with some variables renamed).
dependencies{
// [several remote dependencies]
// ...
compile('myorg:mylib:0.1.0')
}
def ivy_repo = new org.apache.ivy.plugins.resolver.FileSystemResolver()
ivy_repo.name = 'ivy-repo'
ivy_repo.addIvyPattern local_repository + '/ivy/[organisation]/'+
'[module]-ivy-[revision].xml'
ivy_repo.addArtifactPattern local_repository + '/ivy/[organisation]/'+
'[module]-[revision](-[classifier]).[ext]'
ivy_repo.descriptor = 'optional'
ivy_repo.checkmodified = true
repositories{
// [several remote repositories]
// ...
add(ivy_repo)
}
My problem is that when I run my script, once the local libraries are resolved, subsequent calls to the build script make use of the ~/.gradle/cache/myorg:mylib/, rather than the location of my local ivy repository. The Gradle manual has only a few lines mentioning that default local repositories should not use the cache, but I have found now way to actually indiciate that my repository is 'default' and local and thus shouldn't use the cache.
I've tried setting ivy_repo.local = true, or using compile('myorg:mylib:0.1.0'){changing = true}, but neither seems to work.
I don't want to use a flatDir repository because the local library has dependencies which I want my project to find (and I'm using the ivy file associated with the local library to do that now, and it appears that a flatDir repository ignores these sort of files... or maybe I was doing something wrong there?)
Anyone know a solution? Or maybe a better way to accomplish my task with Gradle?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
任何 ivy 解析器都有一个 Resolver.setRepositoryCacheManager() 方法。它采用 RepositoryCacheManager 作为参数。您可以创建自己专门配置的 DefaultRepositoryCacheManager 实例并将其传递给该方法。使用 useOrigin 您可以指示缓存不应用于工件。
<代码>
DefaultRepositoryCacheManager cacheManager = new DefaultRepositoryCacheManager();
缓存管理器.setName(名称);
cacheManager.setUseOrigin(true);
cacheManager.setLockStrategy(new NoLockStrategy());
cacheManager.setIvyPattern(ResolverContainer.DEFAULT_CACHE_IVY_PATTERN);
我们希望在 1.0 中让这变得更加方便。
Any ivy resolver has a
Resolver.setRepositoryCacheManager()
method. It takes a RepositoryCacheManager as an argument. You can create you own specially configured instance of DefaultRepositoryCacheManager and pass it to the method. With useOrigin you indicate that the cache shouldn't be used for artifacts.DefaultRepositoryCacheManager cacheManager = new DefaultRepositoryCacheManager();
cacheManager.setName(name);
cacheManager.setUseOrigin(true);
cacheManager.setLockStrategy(new NoLockStrategy());
cacheManager.setIvyPattern(ResolverContainer.DEFAULT_CACHE_IVY_PATTERN);
We want to make this more convenient in 1.0.