@@ -72,10 +72,27 @@ public void module(String directory) {
72
72
* Register and configure Module located in the given folder, relative to the build root directory.
73
73
*/
74
74
public void module (String directory , Action <Module > action ) {
75
- Module module = getObjects ().newInstance (Module .class , settings .getRootDir ());
76
- module .getDirectory ().set (directory );
75
+ Module module = getObjects ().newInstance (Module .class , new File (settings .getRootDir (), directory ));
77
76
action .execute (module );
78
- includeModule (module , new File (settings .getRootDir (), module .getDirectory ().get ()));
77
+ includeModule (module , new File (settings .getRootDir (), directory ));
78
+ }
79
+
80
+ /**
81
+ * {@link JavaModulesExtension#module(ProjectDescriptor, Action)}
82
+ */
83
+ public void module (ProjectDescriptor project ) {
84
+ module (project , m -> {});
85
+ }
86
+
87
+ /**
88
+ * Register and configure Module already registered as project by an 'include' statement.
89
+ */
90
+ public void module (ProjectDescriptor project , Action <Module > action ) {
91
+ Module module = getObjects ().newInstance (Module .class , project .getProjectDir ());
92
+ module .getArtifact ().set (project .getName ());
93
+ module .getArtifact ().finalizeValue (); // finalize, as the project name can no longer be changed
94
+ action .execute (module );
95
+ configureModule (module , project );
79
96
}
80
97
81
98
/**
@@ -94,7 +111,7 @@ public void directory(String directory, Action<Directory> action) {
94
111
action .execute (moduleDirectory );
95
112
96
113
for (Module module : moduleDirectory .customizedModules .values ()) {
97
- includeModule (module , new File ( modulesDirectory , module .getDirectory (). get ()) );
114
+ includeModule (module , module .directory );
98
115
}
99
116
Provider <List <String >> listProvider = getProviders ().of (ValueModuleDirectoryListing .class , spec -> {
100
117
spec .getParameters ().getExclusions ().set (moduleDirectory .getExclusions ());
@@ -119,7 +136,7 @@ public void versions(String directory) {
119
136
String projectName = Paths .get (directory ).getFileName ().toString ();
120
137
settings .include (projectName );
121
138
settings .project (":" + projectName ).setProjectDir (new File (settings .getRootDir (), directory ));
122
- settings .getGradle ().getLifecycle ().beforeProject (new ApplyJavaModuleVersionsPluginAction (projectName ));
139
+ settings .getGradle ().getLifecycle ().beforeProject (new ApplyJavaModuleVersionsPluginAction (":" + projectName ));
123
140
}
124
141
125
142
private void includeModule (Module module , File projectDir ) {
@@ -128,28 +145,32 @@ private void includeModule(Module module, File projectDir) {
128
145
ProjectDescriptor project = settings .project (":" + artifact );
129
146
project .setProjectDir (projectDir );
130
147
148
+ configureModule (module , project );
149
+ }
150
+
151
+ private void configureModule (Module module , ProjectDescriptor project ) {
131
152
String mainModuleName = null ;
132
- for (String path : module .getModuleInfoPaths ().get ()) {
133
- ModuleInfo moduleInfo = moduleInfoCache .put (projectDir , path ,
134
- module .getArtifact ().get (), module .getGroup (), settings .getProviders ());
135
- if (path .contains ("/main/" )) {
153
+ for (String moduleInfoPath : module .getModuleInfoPaths ().get ()) {
154
+ ModuleInfo moduleInfo = moduleInfoCache .put (project . getProjectDir (), moduleInfoPath ,
155
+ project . getPath (), module .getArtifact ().get (), module .getGroup (), settings .getProviders ());
156
+ if (moduleInfoPath .contains ("/main/" )) {
136
157
mainModuleName = moduleInfo .getModuleName ();
137
158
}
138
159
}
139
160
140
161
String group = module .getGroup ().getOrNull ();
141
162
List <String > plugins = module .getPlugins ().get ();
142
- moduleProjects .add (new ModuleProject (artifact , group , plugins , mainModuleName ));
163
+ moduleProjects .add (new ModuleProject (project . getPath () , group , plugins , mainModuleName ));
143
164
}
144
165
145
166
private static class ModuleProject {
146
- private final String artifact ;
167
+ private final String path ;
147
168
private final String group ;
148
169
private final List <String > plugins ;
149
170
private final String mainModuleName ;
150
171
151
- public ModuleProject (String artifact , String group , List <String > plugins , String mainModuleName ) {
152
- this .artifact = artifact ;
172
+ public ModuleProject (String path , String group , List <String > plugins , String mainModuleName ) {
173
+ this .path = path ;
153
174
this .group = group ;
154
175
this .plugins = plugins ;
155
176
this .mainModuleName = mainModuleName ;
@@ -170,7 +191,7 @@ public ApplyPluginsAction(List<ModuleProject> moduleProjects, ModuleInfoCache mo
170
191
@ Override
171
192
public void execute (Project project ) {
172
193
for (ModuleProject m : moduleProjects ) {
173
- if (project .getName ().equals (m .artifact )) {
194
+ if (project .getPath ().equals (m .path )) {
174
195
if (m .group != null ) project .setGroup (m .group );
175
196
project .getPlugins ().apply (JavaModuleDependenciesPlugin .class );
176
197
project .getExtensions ().getByType (JavaModuleDependenciesExtension .class ).getModuleInfoCache ().set (moduleInfoCache );
@@ -187,15 +208,15 @@ public void execute(Project project) {
187
208
@ NonNullApi
188
209
private static class ApplyJavaModuleVersionsPluginAction implements IsolatedAction <Project > {
189
210
190
- private final String projectName ;
211
+ private final String projectPath ;
191
212
192
- public ApplyJavaModuleVersionsPluginAction (String projectName ) {
193
- this .projectName = projectName ;
213
+ public ApplyJavaModuleVersionsPluginAction (String projectPath ) {
214
+ this .projectPath = projectPath ;
194
215
}
195
216
196
217
@ Override
197
218
public void execute (Project project ) {
198
- if (projectName .equals (project .getName ())) {
219
+ if (projectPath .equals (project .getPath ())) {
199
220
project .getPlugins ().apply (JavaPlatformPlugin .class );
200
221
project .getPlugins ().apply (JavaModuleVersionsPlugin .class );
201
222
project .getExtensions ().getByType (JavaPlatformExtension .class ).allowDependencies ();
0 commit comments