Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle. pass parameters to dependent project build script

I have project ("backend") configuration:

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

And other project ("frontend") configuration is very similar:

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

And when I build the dependant project model- I need to pass a parameter to it's build parameter and do something on condition. So for all projects who needs the sub-projects it will be built according to their needs.

To be more specific: When I build "backtend" - "model"'s project should run some task, but when I build "frontend" I don't.

Is it possible to force clean the sub-project as well?

like image 873
Maladec VampaYa Avatar asked Aug 13 '15 08:08

Maladec VampaYa


1 Answers

You can easily pass parameters from command line, or by properties defined in gradle.properties or in ext. Here's a little project:

/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"
}

If you run gradle hello -Pparam=beta it will print:

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
like image 125
MartinTeeVarga Avatar answered Sep 21 '22 11:09

MartinTeeVarga