@@ -96,12 +96,21 @@ tasks.withType(Test) {
9696}
9797
9898task generateExampleList  {
99+     //  Define the directory and output file
100+     def  examplesDir =  file(' src/main/resources/examples' 
101+     def  outputFile =  file(' src/main/resources/examples/_example_list' 
102+ 
103+     //  Declare the output file as a task output. Otherwise, Gradle is not aware
104+     //  of it and does not include it in the jar file.
105+     outputs. file(outputFile)
106+ 
99107    doLast {
100-         //  Define the directory and output file
101-         def  examplesDir =  new  File (' src/main/resources/examples' 
102-         def  outputFile =  new  File (' src/main/resources/examples/_example_list' 
108+         //  Ensure the output directory exists
109+         if  (! examplesDir. exists()) {
110+             examplesDir. mkdirs()
111+         }
103112
104-         //  Ensure the output file exists
113+         //  Ensure the output file exists and is empty 
105114        outputFile. text =  ' ' 
106115
107116        //  List files and write their names to the output file
@@ -111,13 +120,14 @@ task generateExampleList {
111120            }
112121        }
113122    }
114- }
115123
116- //  Ensure this task is run before the jar is built
117- jar. dependsOn(generateExampleList)
124+ }
118125
126+ //  Since the generateExampleList task generates a file in the resources directory,
127+ //  we need to ensure it is run before the resources are processed.
128+ processResources. dependsOn generateExampleList
119129
120- //  Create a FAT JAR including all dependencies 
130+ //  Configure the jar task 
121131jar  {
122132    archiveBaseName. set(' c3pu' 
123133    archiveVersion. set(version)
@@ -129,6 +139,12 @@ jar {
129139    from {
130140        configurations. runtimeClasspath. collect { it. isDirectory() ?  it :  zipTree(it) }
131141    }
142+     //  Include the output of the generateExampleList task
143+     from(generateExampleList)
144+ 
132145    //  Specify how to handle duplicate entries
133146    duplicatesStrategy =  DuplicatesStrategy . EXCLUDE 
134147}
148+ 
149+ //  Ensure this task is run before the jar is built
150+ jar. dependsOn(generateExampleList)
0 commit comments