LK__
LK__

Reputation: 6713

Configure gradle distribution task

I am using the application plugin and would like to do something like this:

build.gradle

apply from: 'common.gradle'

folder1Files = []
folder1Files << "file1.txt"
folder1Files << "file2.txt"

common.gradle

distributions {
  main {
    contents {
      into ("folder1") { from(folder1Files) }
    }
  }
}

I understand that this can be done by simply adding the apply from after the variable definitions but I was wondering whether there is a more 'bullet proof'/correct way?

In other words, how can I define variables for configuring the distribution task before it is configured?

Upvotes: 1

Views: 1658

Answers (1)

Opal
Opal

Reputation: 84756

It seems that it's possible but You need to exchange variables via project instance. Try:

common.gradle

apply plugin: 'application'

project.ext.folder1Files = []

distributions {
  main {
    contents {
      into ("folder1") { from(folder1Files) }
    }
  }
}

build.gradle

apply from: 'common.gradle'

project.folder1Files << "file1.txt"
project.folder1Files << "file2.txt"

Upvotes: 1

Related Questions