|
12 | 12 |
|
13 | 13 | import javax.inject.Inject; |
14 | 14 |
|
| 15 | +import net.neoforged.gradle.common.runs.run.RunImpl; |
15 | 16 | import net.neoforged.gradle.dsl.common.extensions.sourceset.RunnableSourceSet; |
| 17 | +import net.neoforged.gradle.dsl.common.runs.run.Run; |
16 | 18 | import org.gradle.api.Plugin; |
17 | 19 | import org.gradle.api.Project; |
18 | 20 | import org.gradle.api.Rule; |
@@ -210,43 +212,12 @@ private void configureRuns(@NotNull Project target) { |
210 | 212 | //Ensure a server run is created. |
211 | 213 | runManager.maybeCreate("server"); |
212 | 214 |
|
213 | | - //Ensure a data gen run is created. |
214 | | - runManager.maybeCreate("data"); |
215 | | - |
216 | | - //Configure the data run to have the correct arguments. |
217 | | - runManager.named("data", run -> { |
218 | | - //Add the arguments for the data gen run. |
219 | | - //By default, these are the arguments for the main mod, its output directory, and the default existing resources' directory. |
220 | | - run.getArguments().addAll( |
221 | | - projectExtension.getModId().map(modId -> { |
222 | | - List<String> dataRunArguments = new ArrayList<>(); |
223 | | - dataRunArguments.add("--mod"); |
224 | | - dataRunArguments.add(modId); |
225 | | - dataRunArguments.add("--all"); |
226 | | - dataRunArguments.add("--output"); |
227 | | - dataRunArguments.add(target.file("src/datagen/generated/%s".formatted(modId)).getAbsolutePath()); |
228 | | - dataRunArguments.add("--existing"); |
229 | | - dataRunArguments.add(target.file("src/main/resources/").getAbsolutePath()); |
230 | | - return dataRunArguments; |
231 | | - }) |
232 | | - ); |
233 | | - |
234 | | - //Add the arguments for the additional data gen mods. |
235 | | - run.getArguments().addAll( |
236 | | - extension.getAdditionalDataGenMods().map(mods -> { |
237 | | - if (mods.isEmpty()) { |
238 | | - //When no additional data gen mods are set, we don't need to add any arguments. |
239 | | - return new ArrayList<>(); |
240 | | - } |
241 | | - |
242 | | - //When additional data gen mods are set, we need to add the arguments for each mod. |
243 | | - //Per mod, we need to add the "--existing-mod" argument followed by the mod id. |
244 | | - return mods.stream() |
245 | | - .flatMap(modId -> Stream.of("--existing-mod", modId)) |
246 | | - .collect(Collectors.toList()); |
247 | | - }) |
248 | | - ); |
249 | | - }); |
| 215 | + //Ensure that all configured data runs are created. |
| 216 | + runManager.addAllLater( |
| 217 | + extension.getDataGenerationRuns().map(names -> names.stream() |
| 218 | + .map(name -> createDataRun(target, runManager, projectExtension, extension, name)) |
| 219 | + .toList()) |
| 220 | + ); |
250 | 221 |
|
251 | 222 | //Ensure a game test server run is created. |
252 | 223 | runManager.maybeCreate("gameTestServer"); |
@@ -291,6 +262,46 @@ private void configureRuns(@NotNull Project target) { |
291 | 262 | }); |
292 | 263 | } |
293 | 264 |
|
| 265 | + private static Run createDataRun(final @NotNull Project target, final RunManager runManager, final ProjectExtension projectExtension, final NeoGradleExtension extension, |
| 266 | + final String runName) |
| 267 | + { |
| 268 | + final Run run = target.getObjects().newInstance(RunImpl.class, target, runName); |
| 269 | + |
| 270 | + //Add the arguments for the data gen run. |
| 271 | + //By default, these are the arguments for the main mod, its output directory, and the default existing resources' directory. |
| 272 | + run.getArguments().addAll( |
| 273 | + projectExtension.getModId().map(modId -> { |
| 274 | + List<String> dataRunArguments = new ArrayList<>(); |
| 275 | + dataRunArguments.add("--mod"); |
| 276 | + dataRunArguments.add(modId); |
| 277 | + dataRunArguments.add("--all"); |
| 278 | + dataRunArguments.add("--output"); |
| 279 | + dataRunArguments.add(target.file("src/datagen/generated/%s".formatted(modId)).getAbsolutePath()); |
| 280 | + dataRunArguments.add("--existing"); |
| 281 | + dataRunArguments.add(target.file("src/main/resources/").getAbsolutePath()); |
| 282 | + return dataRunArguments; |
| 283 | + }) |
| 284 | + ); |
| 285 | + |
| 286 | + //Add the arguments for the additional data gen mods. |
| 287 | + run.getArguments().addAll( |
| 288 | + extension.getAdditionalDataGenMods().map(mods -> { |
| 289 | + if (mods.isEmpty()) { |
| 290 | + //When no additional data gen mods are set, we don't need to add any arguments. |
| 291 | + return new ArrayList<>(); |
| 292 | + } |
| 293 | + |
| 294 | + //When additional data gen mods are set, we need to add the arguments for each mod. |
| 295 | + //Per mod, we need to add the "--existing-mod" argument followed by the mod id. |
| 296 | + return mods.stream() |
| 297 | + .flatMap(modId -> Stream.of("--existing-mod", modId)) |
| 298 | + .collect(Collectors.toList()); |
| 299 | + }) |
| 300 | + ); |
| 301 | + |
| 302 | + return run; |
| 303 | + } |
| 304 | + |
294 | 305 | /** |
295 | 306 | * Gets the library configuration for the given source set. |
296 | 307 | * <p> |
|
0 commit comments