88import java .util .stream .Collectors ;
99import javax .inject .Inject ;
1010import org .gradle .api .GradleException ;
11+ import org .gradle .api .Project ;
1112import org .gradle .api .file .ConfigurableFileCollection ;
1213import org .gradle .api .file .DirectoryProperty ;
1314import org .gradle .api .file .FileCollection ;
@@ -84,6 +85,9 @@ public abstract class AbstractBaseTask extends JavaExec {
8485 @ PathSensitive (PathSensitivity .RELATIVE )
8586 @ Optional
8687 private final ConfigurableFileCollection extraSourceDirs ;
88+ @ InputFiles
89+ @ PathSensitive (PathSensitivity .RELATIVE )
90+ private final ConfigurableFileCollection gwtDevRuntimeClasspath ;
8791
8892 /**
8993 * Constructs a new GwtCompileTask.
@@ -110,38 +114,14 @@ public AbstractBaseTask(ObjectFactory objects) {
110114 incremental = objects .property (Boolean .class );
111115 modules = objects .listProperty (String .class );
112116 extraSourceDirs = objects .fileCollection ();
117+ gwtDevRuntimeClasspath = objects .fileCollection ();
113118 }
114119
115- @ Override
116- public void exec () {
117- // Retrieve the main source set
118- SourceSetContainer sourceSets = getProject ().getExtensions ()
119- .getByType (SourceSetContainer .class );
120- SourceSet mainSourceSet = sourceSets .getByName (
121- SourceSet .MAIN_SOURCE_SET_NAME );
122-
123- // Collect all source paths
124- Set <File > allMainSourcePaths = mainSourceSet .getAllSource ().getSrcDirs ();
125- FileCollection outputClasspath = mainSourceSet .getOutput ().getClassesDirs ()
126- .plus (getProject ().files (mainSourceSet .getOutput ().getResourcesDir ()));
127-
128- // Include extra source directories if specified
129- FileCollection allSourcePaths = getProject ().files (allMainSourcePaths );
130- if (!getExtraSourceDirs ().isEmpty ()) {
131- allSourcePaths = allSourcePaths .plus (getExtraSourceDirs ());
132- }
133-
134- // Ensure the classpath includes compiled classes, resources, and source files
135- classpath (
136- allSourcePaths ,
137- outputClasspath ,
138- getProject ().getConfigurations ().getByName (GwtPlugin .GWT_DEV_RUNTIME_CLASSPATH_CONFIGURATION_NAME )
139- );
140-
141- // Log the classpath
142- Logger log = getProject ().getLogger ();
143- getClasspath ().getFiles ().forEach (file -> log .debug ("classpath: {}" , file ));
144-
120+ /**
121+ * Configure task arguments during configuration phase.
122+ * This method should be called from task configuration actions to set up all arguments.
123+ */
124+ public void configureArgs () {
145125 if (getLogLevel ().isPresent ()) {
146126 args ("-logLevel" , getLogLevel ().get ());
147127 }
@@ -155,14 +135,6 @@ public void exec() {
155135 }
156136
157137 if (!isCodeServerTask () && getWar ().isPresent ()) {
158- // Ensure the war directory exists
159- if (!getWar ().get ().getAsFile ().exists ()) {
160- boolean mkdirs = getWar ().get ().getAsFile ().mkdirs ();
161- if (!mkdirs ) {
162- throw new GradleException (
163- "Failed to create war directory: " + getWar ().get ().getAsFile ());
164- }
165- }
166138 args ("-war" , getWar ().get ().getAsFile ().getPath ());
167139 }
168140
@@ -231,8 +203,24 @@ public void exec() {
231203 }
232204
233205 getModules ().get ().forEach (this ::args );
206+ }
207+
208+ @ Override
209+ public void exec () {
210+ // Ensure the war directory exists before executing
211+ if (!isCodeServerTask () && getWar ().isPresent ()) {
212+ if (!getWar ().get ().getAsFile ().exists ()) {
213+ boolean mkdirs = getWar ().get ().getAsFile ().mkdirs ();
214+ if (!mkdirs ) {
215+ throw new GradleException (
216+ "Failed to create war directory: " + getWar ().get ().getAsFile ());
217+ }
218+ }
219+ }
234220
235- // Logging just below visibility. Can turn up access to this package, or log the JavaExec task.
221+ // Log the classpath and args
222+ Logger log = getLogger ();
223+ getClasspath ().getFiles ().forEach (file -> log .debug ("classpath: {}" , file ));
236224 log .info ("classpath: {}" , getClasspath ().getAsPath ());
237225 log .info ("allJvmArgs: {}" , getAllJvmArgs ().stream ().map (arg -> "\" " + arg + "\" " ).collect (Collectors .joining (", " )));
238226 log .info ("main: {}" , getMainClass ().get ());
@@ -416,4 +404,49 @@ public final ListProperty<String> getModules() {
416404 public final ConfigurableFileCollection getExtraSourceDirs () {
417405 return extraSourceDirs ;
418406 }
407+
408+ /**
409+ * The GWT dev runtime classpath
410+ *
411+ * @return The GWT dev runtime classpath
412+ */
413+ public final ConfigurableFileCollection getGwtDevRuntimeClasspath () {
414+ return gwtDevRuntimeClasspath ;
415+ }
416+
417+ /**
418+ * Configures the classpath for this task during configuration phase.
419+ * This method should be called from task configuration actions to avoid Configuration Cache issues.
420+ *
421+ * @param project The project to get source sets and configurations from
422+ */
423+ public void configureClasspath (Project project ) {
424+ SourceSetContainer sourceSets = project .getExtensions ()
425+ .getByType (SourceSetContainer .class );
426+ SourceSet mainSourceSet = sourceSets .getByName (
427+ SourceSet .MAIN_SOURCE_SET_NAME );
428+
429+ // Collect all source paths
430+ FileCollection mainSourcePaths = project .files (mainSourceSet .getAllSource ().getSrcDirs ());
431+ FileCollection outputClasspath = mainSourceSet .getOutput ().getClassesDirs ()
432+ .plus (project .files (mainSourceSet .getOutput ().getResourcesDir ()));
433+
434+ // Include extra source directories if specified
435+ FileCollection allSourcePaths = mainSourcePaths ;
436+ if (!getExtraSourceDirs ().isEmpty ()) {
437+ allSourcePaths = allSourcePaths .plus (getExtraSourceDirs ());
438+ }
439+
440+ // Set up the GWT dev runtime classpath
441+ getGwtDevRuntimeClasspath ().from (
442+ project .getConfigurations ().getByName (GwtPlugin .GWT_DEV_RUNTIME_CLASSPATH_CONFIGURATION_NAME )
443+ );
444+
445+ // Ensure the classpath includes compiled classes, resources, and source files
446+ classpath (
447+ allSourcePaths ,
448+ outputClasspath ,
449+ getGwtDevRuntimeClasspath ()
450+ );
451+ }
419452}
0 commit comments