qwazer
qwazer

Reputation: 7521

Gradle: keep access to extra properties when split build.gradle on several parts

I have the simple gradle.build file

ext {
    port = 10001
}

task expand(type: Copy) {
    // Substitute property tokens in files
    expand(module_name: project.name
            ,     port: port
    )
}

It works like a charm without any problems.

Then I want to refactor my build script and split build.gradle on build.gradle:

apply from: 'rpm.gradle'

ext {
    port = 10001
}

and rpm.gradle:

task expand(type: Copy) {
    expand(module_name: project.name
            ,     port: port
    )
}

Task gradle expand fails with

Error:Could not get unknown property 'port' for task ':expand' of type org.gradle.api.tasks.Copy.

How to resolve it by modifiing only the build.gradle with next constraints:

Upvotes: 0

Views: 343

Answers (1)

Vampire
Vampire

Reputation: 38649

You try to use port before you defined it. Swap that and it should work like

ext {
    port = 10001
}

apply from: 'rpm.gradle'

Upvotes: 1

Related Questions