Gradle存储库作为项目字段 [英] Gradle repositories as project field
问题描述
存储库{
pre>
ivy {
urlhttp://repo.mycompany.com/repo
layoutpattern,{
artifact3rd-party-artifacts / [organization] / [module] / [revision] / [artifact] - [revision]。[ext]
artifactcompany-artifacts / [organization] / [module] / [revision] / [artifact] - [revision]。[ext]
常春藤ivy-files / [organization] / [module] / [revision] /ivy.xml
}
}
}
这很好,但如果我还想使用
uploadArchives
和buildscript
closures,我还需要指定存储库。
@Field def myRepos = {
pre>
ivy {
urlhttp://repo.mycompany.com/repo
layoutpattern,{
artifact3rd-party-artifacts / [organization] / [module] / [revision] / [artifact] - [revision]。[ext]
artifactcompany-artifacts / [organization] / [module] / [revision] / [artifact] - [revision]。[ext]
常春藤ivy-files / [organization] / [module] / [revision] /ivy.xml
}
}
}
这适用于
存储库myRepos
但是对于
buildscript {
repositories myRepos
}
和
uploadArchives {
repositories myRepos
}
给出的是
没有这样的属性:myRepos for class:'org.gradle.api。 internal.initialization.DefaultScript Handler'
我的gradle版本是1.11。
解决方案而不是使用
@Field
,您可以执行def myRepos = ...
。buildscript
块是非常特殊的,如果您想在构建脚本和其他构建脚本之间共享,您必须执行ext。 myRepos = ...
在buildscript
中,并使用buildscript.myRepos
从它引用外面。In gradle, I can specify my repositories with custom layout patterns as
repositories { ivy { url "http://repo.mycompany.com/repo" layout "pattern", { artifact "3rd-party-artifacts/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" artifact "company-artifacts/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" ivy "ivy-files/[organisation]/[module]/[revision]/ivy.xml" } } }
Thats fine, but if I also want to use the
uploadArchives
andbuildscript
closures, I also need to specify the repositories. My idea was to break out the repositories as a field.@Field def myRepos = { ivy { url "http://repo.mycompany.com/repo" layout "pattern", { artifact "3rd-party-artifacts/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" artifact "company-artifacts/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" ivy "ivy-files/[organisation]/[module]/[revision]/ivy.xml" } } }
This works for
repositories myRepos
but for
buildscript { repositories myRepos }
and
uploadArchives { repositories myRepos }
this gives
No such property: myRepos for class: 'org.gradle.api.internal.initialization.DefaultScriptHandler'
My gradle version is 1.11.
解决方案Instead of using
@Field
, you can just dodef myRepos = ...
. Thebuildscript
block is very special, and if you want to share between that and the rest of the build script, you'll have to doext.myRepos = ...
insidebuildscript
, and refer to it usingbuildscript.myRepos
from the outside.这篇关于Gradle存储库作为项目字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文