3636import org .gradlex .javamodule .dependencies .internal .utils .ModuleInfoCache ;
3737import org .gradlex .javamodule .dependencies .internal .utils .ValueModuleDirectoryListing ;
3838
39- import javax .annotation .Nullable ;
4039import javax .inject .Inject ;
4140import java .io .File ;
4241import java .nio .file .Paths ;
42+ import java .util .ArrayList ;
4343import java .util .List ;
4444
4545public abstract class JavaModulesExtension {
4646
4747 private final Settings settings ;
4848 private final ModuleInfoCache moduleInfoCache ;
49+ private final List <ModuleProject > moduleProjects = new ArrayList <>();
4950
5051 @ Inject
5152 public abstract ObjectFactory getObjects ();
@@ -57,6 +58,7 @@ public abstract class JavaModulesExtension {
5758 public JavaModulesExtension (Settings settings ) {
5859 this .settings = settings ;
5960 this .moduleInfoCache = getObjects ().newInstance (ModuleInfoCache .class , true );
61+ settings .getGradle ().getLifecycle ().beforeProject (new ApplyPluginsAction (moduleProjects , moduleInfoCache ));
6062 }
6163
6264 /**
@@ -137,36 +139,46 @@ private void includeModule(Module module, File projectDir) {
137139
138140 String group = module .getGroup ().getOrNull ();
139141 List <String > plugins = module .getPlugins ().get ();
140- settings . getGradle (). getLifecycle (). beforeProject ( new ApplyPluginsAction (artifact , group , plugins , mainModuleName , moduleInfoCache ));
142+ moduleProjects . add ( new ModuleProject (artifact , group , plugins , mainModuleName ));
141143 }
142144
143- @ NonNullApi
144- private static class ApplyPluginsAction implements IsolatedAction <Project >, Action <Project > {
145-
145+ private static class ModuleProject {
146146 private final String artifact ;
147147 private final String group ;
148148 private final List <String > plugins ;
149149 private final String mainModuleName ;
150- private final ModuleInfoCache moduleInfoCache ;
151150
152- public ApplyPluginsAction (String artifact , @ Nullable String group , List <String > plugins , @ Nullable String mainModuleName , ModuleInfoCache moduleInfoCache ) {
151+ public ModuleProject (String artifact , String group , List <String > plugins , String mainModuleName ) {
153152 this .artifact = artifact ;
154153 this .group = group ;
155154 this .plugins = plugins ;
156155 this .mainModuleName = mainModuleName ;
156+ }
157+ }
158+
159+ @ NonNullApi
160+ private static class ApplyPluginsAction implements IsolatedAction <Project >, Action <Project > {
161+
162+ private final List <ModuleProject > moduleProjects ;
163+ private final ModuleInfoCache moduleInfoCache ;
164+
165+ public ApplyPluginsAction (List <ModuleProject > moduleProjects , ModuleInfoCache moduleInfoCache ) {
166+ this .moduleProjects = moduleProjects ;
157167 this .moduleInfoCache = moduleInfoCache ;
158168 }
159169
160170 @ Override
161171 public void execute (Project project ) {
162- if (project .getName ().equals (artifact )) {
163- if (group != null ) project .setGroup (group );
164- project .getPlugins ().apply (JavaModuleDependenciesPlugin .class );
165- project .getExtensions ().getByType (JavaModuleDependenciesExtension .class ).getModuleInfoCache ().set (moduleInfoCache );
166- plugins .forEach (id -> project .getPlugins ().apply (id ));
167- if (mainModuleName != null ) {
168- project .getPlugins ().withType (ApplicationPlugin .class , p ->
169- project .getExtensions ().getByType (JavaApplication .class ).getMainModule ().set (mainModuleName ));
172+ for (ModuleProject m : moduleProjects ) {
173+ if (project .getName ().equals (m .artifact )) {
174+ if (m .group != null ) project .setGroup (m .group );
175+ project .getPlugins ().apply (JavaModuleDependenciesPlugin .class );
176+ project .getExtensions ().getByType (JavaModuleDependenciesExtension .class ).getModuleInfoCache ().set (moduleInfoCache );
177+ m .plugins .forEach (id -> project .getPlugins ().apply (id ));
178+ if (m .mainModuleName != null ) {
179+ project .getPlugins ().withType (ApplicationPlugin .class , p ->
180+ project .getExtensions ().getByType (JavaApplication .class ).getMainModule ().set (m .mainModuleName ));
181+ }
170182 }
171183 }
172184 }
0 commit comments