Gradle存储库作为项目字段 [英] Gradle repositories as project field

查看:94
本文介绍了Gradle存储库作为项目字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Gradle中,我可以使用自定义布局模式指定存储库。

 存储库{
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
}
}
}
pre>

这很好,但如果我还想使用 uploadArchives buildscript closures,我还需要指定存储库。

  @Field def myRepos = {
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
}
}
}
pre>

这适用于

 存储库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 and buildscript 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 do def myRepos = .... The buildscript block is very special, and if you want to share between that and the rest of the build script, you'll have to do ext.myRepos = ... inside buildscript, and refer to it using buildscript.myRepos from the outside.

这篇关于Gradle存储库作为项目字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆