0

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!

pjs
  • 18,696
  • 4
  • 27
  • 56
Bostone
  • 36,858
  • 39
  • 167
  • 227

1 Answers1

1

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.

Fanick
  • 713
  • 7
  • 25
  • thanks! I'm working through your code. It looks like in your example the master project nests children projects. One of the requirements is for project to use a flat structure so the "commonProject is also a master project. Can this be done? – Bostone May 31 '16 at 17:50
  • Depending on meaning of _"...the requirements is for project to use a flat structure so the "commonProject is also a master project_" the needed modifications might vary. But the answer would probably be yes in any case. You can for example `includeFlat("projectA")` from `settings.gradle` within the `commonProject` and initiate `gradle distZip` from inside of the `commonProject`. Simply move all the gradle files into the `commonProject` and switch to `includeFlat` in the `settings.gradle`. If you want to build just one of the projects you can also run for example `gradlew :projectA:distZip`. – Fanick May 31 '16 at 20:16
  • Thanks for your help and enjoy the bounty! – Bostone Jun 01 '16 at 15:06
  • I did what you suggested to flatten the project and now I'm getting this: `* What went wrong: A problem occurred evaluating project ':projectA'. > Project with path ':commonProject' could not be found in project ':projectA'.` – Bostone Jun 06 '16 at 15:30
  • Figured it out - instead of having `commonProjectContent project(path: ':commonProject', configuration: 'sharedContent')` in `dependencies` section it is actually `commonProjectContent project(path: ':', configuration: 'sharedContent')` because you simply refer to the root project as `:` – Bostone Jun 06 '16 at 20:36