3

I have multi-project where I want to attach resources from different locations (sub-projects that generate them) but also place them in different output directories.

wrapper (parent)
|--frontend (child)
|  |--build/dist
|     |--js
|     |  |-- ...
|     |--css
|        |-- ...
|--lib (child)
   |--build/dist
      |--python
         |-- ...

I need for wrapper (parent) to treat both of child projects' build/dist as resource, BUT placed in different outputDir.

  • frontend/build/dist would be in ./wrapper/build/resources/main/static
  • lib/build/dist would be in ./wrapper/build/resources/main

Goal is to have given resource of sourceSet main be appended with static directory when moving it to outputDir.

Note that outputDir is NOT jar task. This is not packaging issue, but outputDir issue.

sourceSets {
    main {
        resources {
             srcDirs [
                 project(':frontend').projectDir.absolutePath + '/build/dist'
                 project(':lib').projectDir.absolutePath + '/build/dist'
             ]
        }
        output.resourcesDir project.buildDir.absolutePath + '/resources/main/static'
    }
}

Above will add resources to main sourceSet, but they will have the same output.resourceDir.

Final questions

  1. Is there syntax that allows defining output for given src? Can you give me example?
  2. If not (yet?), I though about defining more than one sourceSet. Basically define main1 and main2, this would work fine, but I have some problems making those sourceSets be child of main. In other words - if you define custom sourceSet (not main or test) you need to make it compile - how? I know I can command: gradle build sourceSetName to invoke specific custom sourceSet compilation, how can I do it so it is dependency to main?

I am using Gradle 4.10.1 with java (and eclipse) plugins.

Ernio
  • 948
  • 10
  • 25
  • see this answer: https://stackoverflow.com/a/52521936/549372 ...because what you do is merging resource directories - which only might work when the destination sub-directories are already present in the two `srcDirs`. – Martin Zeitler Oct 25 '18 at 06:53
  • @MartinZeitler I was considering creating "fake" task pipeline imitating copying (Gradle uses Copy task to resources->outputDir), but I really want to preserve mechanism of java plugin because it's base for generating IDE classpaths (eclipse in my case). If I go this way I will also have to define whole bunch of eclipse configurations to mirror gradle's build process. Using only sourceSets (if such syntax exists) setups unified front with IDE plugins. For now I will also try generating /static/ already in dist folder, but in future that might not be enough (this thread is simplified problem). – Ernio Oct 25 '18 at 07:32
  • these are `resources { }` `SourceSet` ...to add `build/dist` as `srcDirs` seems strange. in general, `src` should be the build input, not the build output. version control hooks can also be used for such automation ...eg. to have a further repository, which performs to combined build. – Martin Zeitler Oct 25 '18 at 23:53

0 Answers0