21
21
import org .gradle .api .artifacts .MinimalExternalModuleDependency ;
22
22
import org .gradle .api .artifacts .VersionCatalog ;
23
23
import org .gradle .api .artifacts .VersionCatalogsExtension ;
24
- import org .gradle .api .artifacts .dsl .DependencyHandler ;
25
24
import org .gradle .api .provider .Property ;
26
25
import org .gradle .api .provider .Provider ;
27
26
27
+ import java .util .List ;
28
28
import java .util .Optional ;
29
+ import java .util .Set ;
29
30
30
31
/**
31
32
* Represents a dependency which is automatically
@@ -43,36 +44,42 @@ public record AutomaticDependency(
43
44
) {
44
45
public void applyTo (Project p ) {
45
46
p .getPlugins ().withType (MicronautComponentPlugin .class , unused -> {
46
- DependencyHandler dependencyHandler = p .getDependencies ();
47
- MicronautExtension micronautExtension = p .getExtensions ().getByType (MicronautExtension .class );
48
- dependencyHandler .addProvider (configuration , p .getProviders ().provider (() -> {
49
- if (versionProperty .isPresent ()) {
50
- Property <String > provider = (Property <String >) micronautExtension .getExtensions ().findByName (versionProperty .get ().dslName ());
51
- if (provider != null && provider .isPresent ()) {
52
- return dependencyHandler .create (coordinates + ":" + provider .get ());
47
+ var dependencyHandler = p .getDependencies ();
48
+ var micronautExtension = p .getExtensions ().getByType (MicronautExtension .class );
49
+ var ignoredDependencies = micronautExtension .getIgnoredAutomaticDependencies ();
50
+ p .getConfigurations ().getByName (configuration ).getDependencies ().addAllLater (
51
+ p .getProviders ().provider (() -> {
52
+ var ignored = ignoredDependencies .getOrElse (Set .of ());
53
+ if (ignored .contains (coordinates )) {
54
+ return List .of ();
53
55
}
54
- }
55
- // If the Micronaut version catalog is applied via the settings plugin, we won't use an "empty" version
56
- // but fetch it from the catalog if possible
57
- VersionCatalogsExtension versionCatalogs = p .getExtensions ().findByType (VersionCatalogsExtension .class );
58
- if (versionCatalogs != null ) {
59
- Optional <VersionCatalog > mn = versionCatalogs .find ("mn" );
60
- if (mn .isPresent ()) {
61
- VersionCatalog micronautCatalog = mn .get ();
62
- Optional <Provider <MinimalExternalModuleDependency >> dependencyProvider = micronautCatalog .getLibraryAliases ()
56
+ if (versionProperty .isPresent ()) {
57
+ Property <String > provider = (Property <String >) micronautExtension .getExtensions ().findByName (versionProperty .get ().dslName ());
58
+ if (provider != null && provider .isPresent ()) {
59
+ return List .of (dependencyHandler .create (coordinates + ":" + provider .get ()));
60
+ }
61
+ }
62
+ // If the Micronaut version catalog is applied via the settings plugin, we won't use an "empty" version
63
+ // but fetch it from the catalog if possible
64
+ VersionCatalogsExtension versionCatalogs = p .getExtensions ().findByType (VersionCatalogsExtension .class );
65
+ if (versionCatalogs != null ) {
66
+ Optional <VersionCatalog > mn = versionCatalogs .find ("mn" );
67
+ if (mn .isPresent ()) {
68
+ VersionCatalog micronautCatalog = mn .get ();
69
+ Optional <Provider <MinimalExternalModuleDependency >> dependencyProvider = micronautCatalog .getLibraryAliases ()
63
70
.stream ()
64
71
.map (micronautCatalog ::findLibrary )
65
72
.map (Optional ::get )
66
73
.filter (d -> coordinates .equals (d .get ().getModule ().toString ()))
67
74
.findFirst ();
68
- if (dependencyProvider .isPresent ()) {
69
- return dependencyProvider .get ().get ();
75
+ if (dependencyProvider .isPresent ()) {
76
+ return List .of (dependencyProvider .get ().get ());
77
+ }
70
78
}
71
79
}
72
- }
73
- return dependencyHandler .create (coordinates );
74
- }));
75
-
80
+ return List .of (dependencyHandler .create (coordinates ));
81
+ })
82
+ );
76
83
});
77
84
}
78
85
0 commit comments