Define multiple output dirs for resources in sourceSet in Gradle

Viewed 436

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.

0 Answers
Related