27
27
public abstract class JavaModuleDependenciesPlugin implements Plugin <Project > {
28
28
29
29
private final Map <File , ModuleInfo > moduleInfo = new HashMap <>();
30
+ private boolean warnForMissingCatalog ;
30
31
31
32
@ Override
32
33
public void apply (Project project ) {
@@ -37,12 +38,13 @@ public void apply(Project project) {
37
38
project .getPlugins ().apply (JavaPlugin .class );
38
39
39
40
VersionCatalogsExtension versionCatalogs = project .getExtensions ().findByType (VersionCatalogsExtension .class );
41
+ warnForMissingCatalog = versionCatalogs == null ;
40
42
41
43
JavaModuleDependenciesExtension javaModuleDependenciesExtension = project .getExtensions ().create (
42
- JAVA_MODULE_DEPENDENCIES , JavaModuleDependenciesExtension .class , versionCatalogs , project . getLogger () );
44
+ JAVA_MODULE_DEPENDENCIES , JavaModuleDependenciesExtension .class , versionCatalogs );
43
45
javaModuleDependenciesExtension .getOwnModuleNamesPrefix ().convention (
44
46
project .provider (() -> project .getGroup ().toString ()));
45
- javaModuleDependenciesExtension .getWarnForMissingVersions ().convention (true );
47
+ javaModuleDependenciesExtension .getWarnForMissingVersions ().convention (versionCatalogs != null );
46
48
javaModuleDependenciesExtension .getVersionCatalogName ().convention ("libs" );
47
49
48
50
SourceSetContainer sourceSets = project .getExtensions ().getByType (SourceSetContainer .class );
@@ -87,34 +89,49 @@ private void findAndReadModuleInfo(ModuleInfo.Directive moduleDirective, SourceS
87
89
}
88
90
}
89
91
90
- private void declareDependency (String moduleName , Provider <RegularFile > moduleInfoFile , Project project , Configuration configuration , JavaModuleDependenciesExtension javaModuleDependenciesExtension ) {
92
+ private void declareDependency (String moduleName , Provider <RegularFile > moduleInfoFile , Project project , Configuration configuration , JavaModuleDependenciesExtension javaModuleDependencies ) {
91
93
if (JDKInfo .MODULES .contains (moduleName )) {
92
94
// The module is part of the JDK, no dependency required
93
95
return ;
94
96
}
95
97
96
- String ownModuleNamesPrefix = javaModuleDependenciesExtension .getOwnModuleNamesPrefix ().forUseAtConfigurationTime ().get ();
97
- String ga = javaModuleDependenciesExtension .ga (moduleName );
98
- String projectName = moduleName .startsWith (ownModuleNamesPrefix + "." ) ? moduleName .substring (ownModuleNamesPrefix .length () + 1 ) : null ;
98
+ String ownModuleNamesPrefix = javaModuleDependencies .getOwnModuleNamesPrefix ().forUseAtConfigurationTime ().get ();
99
+ String ga = javaModuleDependencies .ga (moduleName );
100
+ String projectName = moduleName .startsWith (ownModuleNamesPrefix + "." ) ? moduleName .substring (ownModuleNamesPrefix .length () + 1 ) : null ;
99
101
100
102
if (projectName != null ) {
101
103
project .getDependencies ().add (
102
104
configuration .getName (),
103
105
project .project (":" + projectName )
104
106
);
105
107
} else if (ga != null ) {
106
- project .getDependencies ().add (
107
- configuration .getName (), javaModuleDependenciesExtension .gav (moduleName ));
108
+ Map <String , Object > gav = javaModuleDependencies .gav (moduleName );
109
+ project .getDependencies ().add (configuration .getName (), gav );
110
+ if (!gav .containsKey ("version" )) {
111
+ warnVersionMissing (moduleName , ga , moduleInfoFile , project , javaModuleDependencies );
112
+ }
108
113
} else {
109
114
throw new RuntimeException ("No mapping registered for module: " + moduleDebugInfo (moduleName , moduleInfoFile , project .getRootDir ()) +
110
115
" - use 'javaModuleDependencies.moduleNameToGA.put()' to add mapping." );
111
116
}
112
117
}
113
118
114
- private String moduleDebugInfo (String moduleName , Provider <RegularFile > moduleInfo , File rootDir ) {
119
+ private void warnVersionMissing (String moduleName , String ga , Provider <RegularFile > moduleInfoFile , Project project , JavaModuleDependenciesExtension javaModuleDependencies ) {
120
+ if (warnForMissingCatalog ) {
121
+ project .getLogger ().warn ("[WARN] [Java Module Dependencies] Version catalog feature not enabled in settings.gradle(.kts) - add 'enableFeaturePreview(\" VERSION_CATALOGS\" )'" );
122
+ warnForMissingCatalog = false ;
123
+ }
124
+
125
+ if (javaModuleDependencies .getWarnForMissingVersions ().forUseAtConfigurationTime ().get ()) {
126
+ project .getLogger ().warn ("[WARN] [Java Module Dependencies] No version defined in catalog - " + ga + " - "
127
+ + moduleDebugInfo (moduleName .replace ('.' , '_' ), moduleInfoFile , project .getRootDir ()));
128
+ }
129
+ }
130
+
131
+ private String moduleDebugInfo (String moduleName , Provider <RegularFile > moduleInfoFile , File rootDir ) {
115
132
return moduleName
116
133
+ " (required in "
117
- + moduleInfo .forUseAtConfigurationTime ().get ().getAsFile ().getAbsolutePath ().substring (rootDir .getAbsolutePath ().length () + 1 )
134
+ + moduleInfoFile .forUseAtConfigurationTime ().get ().getAsFile ().getAbsolutePath ().substring (rootDir .getAbsolutePath ().length () + 1 )
118
135
+ ")" ;
119
136
}
120
137
0 commit comments