@@ -96,12 +96,21 @@ tasks.withType(Test) {
96
96
}
97
97
98
98
task 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
+
99
107
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
+ }
103
112
104
- // Ensure the output file exists
113
+ // Ensure the output file exists and is empty
105
114
outputFile. text = ' '
106
115
107
116
// List files and write their names to the output file
@@ -111,13 +120,14 @@ task generateExampleList {
111
120
}
112
121
}
113
122
}
114
- }
115
123
116
- // Ensure this task is run before the jar is built
117
- jar. dependsOn(generateExampleList)
124
+ }
118
125
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
119
129
120
- // Create a FAT JAR including all dependencies
130
+ // Configure the jar task
121
131
jar {
122
132
archiveBaseName. set(' c3pu' )
123
133
archiveVersion. set(version)
@@ -129,6 +139,12 @@ jar {
129
139
from {
130
140
configurations. runtimeClasspath. collect { it. isDirectory() ? it : zipTree(it) }
131
141
}
142
+ // Include the output of the generateExampleList task
143
+ from(generateExampleList)
144
+
132
145
// Specify how to handle duplicate entries
133
146
duplicatesStrategy = DuplicatesStrategy . EXCLUDE
134
147
}
148
+
149
+ // Ensure this task is run before the jar is built
150
+ jar. dependsOn(generateExampleList)
0 commit comments