As I’m not sure if it’s a bug or a configuration issue on my side, I would like to ask for help here before submitting a bug on GitHub.
I have the following project structure using Gradle wrapper and Gradle 4.7 (I have omitted Gradle wrapper files in the list below). I have also posted this code in a GitHub repository
. build.gradle (empty file)
settings.gradle:
rootProject.name = 'dist-test'
include 'module-a'
include 'dist'
The issue with my configuration is that when I run ./gradlew :dist:buildDist with the following block uncommented in dist/build.gradle:
into('generatedFiles') {
from configurations.generatedFiles
}
then doFirst block prints an empty list of files available in generatedFiles configuration. On the other hand when I comment out into('generatedFiles') block then doFirst block correctly prints two files available in generatedFiles configuration (dist-test/module-a/build/module-files/module-a-file-1.txt and dist-test/module-a/build/module-files/module-a-file-2.txt)
Is it a bug or do I have an issue in my configuration?
Your configuration of the generateModuleFiles task is problematic. You don’t configure the artifacts until the task executes, but the definition of the artifacts should be what causes the task to run from the intra-project configuration dependencies.
Also, << is deprecated. You should use doFirst{} / doLast {} and only include the actual work in the task action. The artifacts should be configured at configuration time, and either use task outputs or declare builtBy to make sure the appropriate relationship is established.
While your generateModuleFiles task looks a lot better now, I would still recommend that you maintain the artifacts in the producing project, and consuming them the way that you were previously. While it may seem unnecessary, it is better practice to couple your dist project to the exposed artifacts, which are designed for this, rather than an implementation detail of the producing project. Directly using the task output from another project introduces unnecessary coupling.
Am I correct that when using artifacts I would have to use zip or jar files to package all the files generated by my task? Would it mean I would have to have two tasks in module-a, one that produces the files and another that zips them and publish as an artifact?