@@ -193,6 +193,7 @@ public static ResolvedDependencyBuilder getProjectArtifact(Project project, bool
193
193
194
194
initProjectModule (project , mainModule , sourceSets .getByName (SourceSet .MAIN_SOURCE_SET_NAME ), ArtifactSources .MAIN );
195
195
if (workspaceDiscovery ) {
196
+ appArtifact .setReloadable ();
196
197
final TaskCollection <Test > testTasks = project .getTasks ().withType (Test .class );
197
198
if (!testTasks .isEmpty ()) {
198
199
final Map <File , SourceSet > sourceSetsByClassesDir = new HashMap <>();
@@ -241,18 +242,36 @@ private static void collectDestinationDirs(Collection<SourceDir> sources, final
241
242
private void collectExtensionDependencies (Project project , Configuration deploymentConfiguration ,
242
243
ApplicationModelBuilder modelBuilder ) {
243
244
final ResolvedConfiguration rc = deploymentConfiguration .getResolvedConfiguration ();
245
+ final Set <ArtifactKey > processedDeps = new HashSet <>();
244
246
for (var dep : rc .getFirstLevelModuleDependencies ()) {
245
- processDeploymentDependency (project , dep , modelBuilder , false );
247
+ processDeploymentDependency (project , dep , modelBuilder , false , processedDeps );
246
248
}
247
249
}
248
250
249
251
private static void processDeploymentDependency (Project project , ResolvedDependency resolvedDep ,
250
- ApplicationModelBuilder modelBuilder , boolean clearReloadableFlag ) {
251
- boolean processChildren = false ;
252
- for (var a : resolvedDep .getModuleArtifacts ()) {
253
- ResolvedDependencyBuilder dep = modelBuilder .getDependency (getKey (a ));
252
+ ApplicationModelBuilder modelBuilder , boolean clearReloadableFlag , Set <ArtifactKey > processedDeps ) {
253
+ final Set <ResolvedArtifact > resolvedArtifacts = resolvedDep .getModuleArtifacts ();
254
+ boolean processChildren = resolvedArtifacts .isEmpty ();
255
+ for (var a : resolvedArtifacts ) {
256
+ final ArtifactKey artifactKey = getKey (a );
257
+ if (!processedDeps .add (artifactKey )) {
258
+ continue ;
259
+ }
260
+ processChildren = true ;
261
+ ResolvedDependencyBuilder dep = modelBuilder .getDependency (artifactKey );
254
262
if (dep == null ) {
255
- if (a .getId ().getComponentIdentifier () instanceof ProjectComponentIdentifier projectComponentIdentifier ) {
263
+ if (isApplicationRoot (modelBuilder , artifactKey )) {
264
+ // An application root artifact may be found among the dependencies in a could of cases:
265
+ // test fixtures in an application project and as a deployment module in an extension project
266
+ // running deployment module tests.
267
+ // In case of test fixtures, the root artifact does not have to be added to the model as a dependency,
268
+ // it can simply be skipped.
269
+ // In case of a deployment test, it has to be added as a dependency, since otherwise, the deployment
270
+ // module will appear to be missing.
271
+ // This part here looks like a hack but appears to work for both cases so far.
272
+ dep = modelBuilder .getApplicationArtifact ();
273
+ } else if (a .getId ()
274
+ .getComponentIdentifier () instanceof ProjectComponentIdentifier projectComponentIdentifier ) {
256
275
var includedBuild = ToolingUtils .includedBuild (project ,
257
276
projectComponentIdentifier .getBuild ().getBuildPath ());
258
277
final Project projectDep ;
@@ -297,22 +316,26 @@ private static void processDeploymentDependency(Project project, ResolvedDepende
297
316
}
298
317
}
299
318
if (dep != null ) {
300
- if (!dep .isDeploymentCp ()) {
301
- dep .setDeploymentCp ();
302
- processChildren = true ;
319
+ if (dep .isRuntimeExtensionArtifact ()) {
320
+ clearReloadableFlag = true ;
303
321
}
304
- if (clearReloadableFlag ) {
322
+ dep .setDeploymentCp ();
323
+ if (clearReloadableFlag && dep != modelBuilder .getApplicationArtifact ()) {
305
324
dep .clearFlag (DependencyFlags .RELOADABLE );
306
325
}
307
326
}
308
327
}
309
328
if (processChildren ) {
310
329
for (var child : resolvedDep .getChildren ()) {
311
- processDeploymentDependency (project , child , modelBuilder , clearReloadableFlag );
330
+ processDeploymentDependency (project , child , modelBuilder , clearReloadableFlag , processedDeps );
312
331
}
313
332
}
314
333
}
315
334
335
+ private static boolean isApplicationRoot (ApplicationModelBuilder modelBuilder , ArtifactKey artifactKey ) {
336
+ return modelBuilder .getApplicationArtifact ().getKey ().equals (artifactKey );
337
+ }
338
+
316
339
private static ResolvedDependencyBuilder addArtifactDependency (Project project , ApplicationModelBuilder modelBuilder ,
317
340
ResolvedArtifact a ) {
318
341
ResolvedDependencyBuilder dep = modelBuilder .getDependency (getKey (a ));
@@ -350,9 +373,7 @@ private void collectDependencies(ResolvedConfiguration configuration, Resolvable
350
373
351
374
final Set <File > artifactFiles = getArtifactFilesOrNull (configuration , dependencies );
352
375
for (ResolvedDependency d : configuration .getFirstLevelModuleDependencies ()) {
353
- collectDependencies (d , workspaceDiscovery , project , artifactFiles , new HashSet <>(),
354
- modelBuilder ,
355
- wsModule ,
376
+ collectDependencies (d , workspaceDiscovery , project , artifactFiles , modelBuilder , wsModule ,
356
377
(byte ) (COLLECT_TOP_EXTENSION_RUNTIME_NODES | COLLECT_DIRECT_DEPS | COLLECT_RELOADABLE_MODULES ));
357
378
}
358
379
@@ -403,86 +424,94 @@ private static Set<File> getArtifactFilesOrNull(ResolvedConfiguration configurat
403
424
}
404
425
405
426
private void collectDependencies (org .gradle .api .artifacts .ResolvedDependency resolvedDep , boolean workspaceDiscovery ,
406
- Project project , Set <File > artifactFiles , Set < ArtifactKey > processedModules , ApplicationModelBuilder modelBuilder ,
427
+ Project project , Set <File > artifactFiles , ApplicationModelBuilder modelBuilder ,
407
428
WorkspaceModule .Mutable parentModule ,
408
429
byte flags ) {
409
430
WorkspaceModule .Mutable projectModule = null ;
410
- for (ResolvedArtifact a : resolvedDep .getModuleArtifacts ()) {
431
+ final Set <ResolvedArtifact > resolvedArtifacts = resolvedDep .getModuleArtifacts ();
432
+ boolean processChildren = resolvedArtifacts .isEmpty ();
433
+ for (ResolvedArtifact a : resolvedArtifacts ) {
411
434
if (!isDependency (a )) {
412
435
continue ;
413
436
}
414
- var depBuilder = modelBuilder .getDependency (getKey (a ));
415
- if (depBuilder != null ) {
416
- if (isFlagOn (flags , COLLECT_DIRECT_DEPS )) {
417
- depBuilder .setDirect (true );
418
- }
437
+ final ArtifactKey artifactKey = getKey (a );
438
+ if (isApplicationRoot (modelBuilder , artifactKey )) {
419
439
continue ;
420
440
}
421
- final ArtifactCoords depCoords = getArtifactCoords (a );
422
- depBuilder = ResolvedDependencyBuilder .newInstance ()
423
- .setCoords (depCoords )
424
- .setRuntimeCp ();
425
- if (isFlagOn (flags , COLLECT_DIRECT_DEPS )) {
426
- depBuilder .setDirect (true );
427
- flags = clearFlag (flags , COLLECT_DIRECT_DEPS );
428
- }
429
- if (parentModule != null ) {
430
- parentModule .addDependency (new ArtifactDependency (depCoords ));
431
- }
432
-
433
- PathCollection paths = null ;
434
- if (workspaceDiscovery && a .getId ().getComponentIdentifier () instanceof ProjectComponentIdentifier compId ) {
435
- Project projectDep = project .getRootProject ().findProject (compId .getProjectPath ());
441
+ var depBuilder = modelBuilder .getDependency (artifactKey );
442
+ if (depBuilder == null ) {
443
+ processChildren = true ;
444
+ final ArtifactCoords depCoords = getArtifactCoords (a );
445
+ depBuilder = ResolvedDependencyBuilder .newInstance ()
446
+ .setCoords (depCoords )
447
+ .setRuntimeCp ();
448
+ if (parentModule != null ) {
449
+ parentModule .addDependency (new ArtifactDependency (depCoords ));
450
+ }
436
451
437
- final String classifier = a .getClassifier ();
438
- if (classifier == null || classifier .isEmpty ()) {
439
- final IncludedBuild includedBuild = ToolingUtils .includedBuild (project .getRootProject (),
440
- compId .getBuild ().getBuildPath ());
441
- if (includedBuild != null ) {
442
- if (includedBuild instanceof IncludedBuildInternal ib ) {
443
- projectDep = ToolingUtils .includedBuildProject (ib , compId .getProjectPath ());
444
- }
445
- if (projectDep != null ) {
446
- initProjectModuleAndBuildPaths (projectDep , a , modelBuilder , depBuilder );
452
+ PathCollection paths = null ;
453
+ if (workspaceDiscovery && a .getId ().getComponentIdentifier () instanceof ProjectComponentIdentifier compId ) {
454
+ Project projectDep = project .getRootProject ().findProject (compId .getProjectPath ());
455
+
456
+ final String classifier = a .getClassifier ();
457
+ if (classifier == null || classifier .isEmpty ()) {
458
+ final IncludedBuild includedBuild = ToolingUtils .includedBuild (project .getRootProject (),
459
+ compId .getBuild ().getBuildPath ());
460
+ if (includedBuild != null ) {
461
+ if (includedBuild instanceof IncludedBuildInternal ib ) {
462
+ projectDep = ToolingUtils .includedBuildProject (ib , compId .getProjectPath ());
463
+ }
464
+ if (projectDep != null ) {
465
+ initProjectModuleAndBuildPaths (projectDep , a , modelBuilder , depBuilder );
466
+ } else {
467
+ final PathList .Builder pathBuilder = PathList .builder ();
468
+ addSubstitutedProject (pathBuilder , includedBuild .getProjectDir ());
469
+ paths = pathBuilder .build ();
470
+ }
447
471
} else {
448
- final PathList .Builder pathBuilder = PathList .builder ();
449
- addSubstitutedProject (pathBuilder , includedBuild .getProjectDir ());
450
- paths = pathBuilder .build ();
472
+ initProjectModuleAndBuildPaths (projectDep , a , modelBuilder , depBuilder );
451
473
}
452
474
} else {
453
475
initProjectModuleAndBuildPaths (projectDep , a , modelBuilder , depBuilder );
454
476
}
455
- } else {
456
- initProjectModuleAndBuildPaths (projectDep , a , modelBuilder , depBuilder );
457
477
}
458
- }
459
478
460
- depBuilder .setResolvedPaths (paths == null ? PathList .of (a .getFile ().toPath ()) : paths );
461
- if (processQuarkusDependency (depBuilder , modelBuilder )) {
462
- if (isFlagOn (flags , COLLECT_TOP_EXTENSION_RUNTIME_NODES )) {
479
+ depBuilder .setResolvedPaths (paths == null ? PathList .of (a .getFile ().toPath ()) : paths );
480
+ if (processQuarkusDependency (depBuilder , modelBuilder )) {
481
+ flags = clearFlag (flags , COLLECT_RELOADABLE_MODULES );
482
+ }
483
+ modelBuilder .addDependency (depBuilder );
484
+
485
+ if (artifactFiles != null ) {
486
+ artifactFiles .add (a .getFile ());
487
+ }
488
+ }
489
+ if (projectModule == null && depBuilder .getWorkspaceModule () != null ) {
490
+ projectModule = depBuilder .getWorkspaceModule ().mutable ();
491
+ }
492
+ if (isFlagOn (flags , COLLECT_DIRECT_DEPS )) {
493
+ depBuilder .setDirect (true );
494
+ flags = clearFlag (flags , COLLECT_DIRECT_DEPS );
495
+ }
496
+ if (depBuilder .isRuntimeExtensionArtifact ()) {
497
+ if (isFlagOn (flags , COLLECT_RELOADABLE_MODULES )) {
498
+ flags = clearFlag (flags , COLLECT_RELOADABLE_MODULES );
499
+ processChildren = true ;
500
+ }
501
+ if (isFlagOn (flags , COLLECT_TOP_EXTENSION_RUNTIME_NODES )
502
+ && !depBuilder .isFlagSet (DependencyFlags .TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT )) {
463
503
depBuilder .setFlags (DependencyFlags .TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT );
464
504
flags = clearFlag (flags , COLLECT_TOP_EXTENSION_RUNTIME_NODES );
465
505
}
466
- flags = clearFlag (flags , COLLECT_RELOADABLE_MODULES );
467
506
}
468
507
if (!isFlagOn (flags , COLLECT_RELOADABLE_MODULES )) {
469
508
depBuilder .clearFlag (DependencyFlags .RELOADABLE );
470
509
}
471
- modelBuilder .addDependency (depBuilder );
472
- if (projectModule == null && depBuilder .getWorkspaceModule () != null ) {
473
- projectModule = depBuilder .getWorkspaceModule ().mutable ();
474
- }
475
-
476
- if (artifactFiles != null ) {
477
- artifactFiles .add (a .getFile ());
478
- }
479
510
}
480
511
481
- processedModules .add (ArtifactKey .ga (resolvedDep .getModuleGroup (), resolvedDep .getModuleName ()));
482
- for (org .gradle .api .artifacts .ResolvedDependency child : resolvedDep .getChildren ()) {
483
- if (!processedModules .contains (ArtifactKey .ga (child .getModuleGroup (), child .getModuleName ()))) {
484
- collectDependencies (child , workspaceDiscovery , project , artifactFiles , processedModules ,
485
- modelBuilder , projectModule , flags );
512
+ if (processChildren ) {
513
+ for (org .gradle .api .artifacts .ResolvedDependency child : resolvedDep .getChildren ()) {
514
+ collectDependencies (child , workspaceDiscovery , project , artifactFiles , modelBuilder , projectModule , flags );
486
515
}
487
516
}
488
517
}
0 commit comments