当前位置 : 主页 > 手机开发 > 其它 >

摇篮.将参数传递给依赖项目构建脚本

来源:互联网 收集:自由互联 发布时间:2021-06-22
我有项目(“后端”)配置: dependencies { compile project(':model') //I would like to pass some params into this being build. ... 和其他项目(“前端”)配置非常相似: dependencies { compile project(':model') //but fro
我有项目(“后端”)配置:

dependencies {
    compile project(':model') //I would like to pass some params into this being build.
    ...

和其他项目(“前端”)配置非常相似:

dependencies {
    compile project(':model') //but from this project I will not pass params.
    ...

当我构建依赖项目模型时 – 我需要将参数传递给它的构建参数并在条件上执行某些操作.因此,对于需要子项目的所有项目,它将根据他们的需求进行构建.

更具体一点:当我构建“后退” – “模型”的项目应该运行一些任务,但是当我构建“前端”时我不这样做.

是否有可能强制清理子项目?

您可以轻松地从命令行传递参数,也可以通过gradle.properties或ext中定义的属性传递参数.这是一个小项目:

/build.gradle

ext {
    var = "alpha"
}

task hello {
    println "Name: $project.name"
    println "Var: $var"
    println "Param: $param"
    println "Prop: $prop"
}

/gradle.properties

prop=gama

/settings.gradle

project.name = 'foo'

include 'bar'

/bar/build.gradle

task hello {
    println "Name: $project.name"
    println "Var: $var"
    println "Param: $param"
    println "Prop: $prop"
}

如果你运行gradle hello -Pparam = beta它会打印:

Name: foo
Var: alpha
Param: beta
Prop: gama
Name: bar
Var: alpha
Param: beta
Prop: gama
:hello UP-TO-DATE
:bar:hello UP-TO-DATE
网友评论