Bostone
Bostone

Reputation: 37126

Individual distributions for Gradle multi-project

I have a number of very similar (non-Java) projects that needs to generate Zip/Tar distribution. Generally each project simply has a distributions section that copies various files/directories and assembles the archive. I would like to extract common code to the separate "common" project but perform the build from the child project(s) so I can generate one archive based on the flavor I need. The common code is simply a directory(s) that need to be included into archive(s)

I probably will never run a build from the parent to generate multiple distributions.

I need to copy common files first and then add/overwrite files from the child project. I looked at examples from samples/userguide/multiproject and would like to use a flat structure. But these examples are pretty spartan so any examples would be greatly appreciated!

Upvotes: 0

Views: 559

Answers (1)

Fanick
Fanick

Reputation: 733

Please look into this sample project https://github.com/fanick1/so-individual-distributions-for-gradle-multi-project

From what you have written in the question I assume that you are using the distribution plugin. The repository contains a multi-project consisting of one project (commonProject) with let's say common content:

commonProject/src/
  - commonFiles/
  - customFiles/customFile.txt

and two child projects (projectA, projectB) which are basically identical:

  project[A|B]/src/
    - customFiles/customFile.txt
    - files[A|B]/

You can run gradlew distZip which will create distribution zip files in each of the sub project in the /build/distributions folder. The child projects contain folder customFiles which is also located in the commonProject. It's content in the output zip file will be eventually overwritten by content in respective child projects if there is a file with same name. Basically what this means is that file /customFiles/customFile.txt will be overwritten. Content in /commonFiles will be always copied into the child projects' distribution zip files. Hope this helps.

Upvotes: 1

Related Questions