Skip to content

Commit 184a895

Browse files
authored
Merge pull request #109 from jiakuan/feature/108-configuration-cache-compatibility
Fix Configuration Cache compatibility (#108)
2 parents 0809265 + edae5f6 commit 184a895

File tree

5 files changed

+99
-43
lines changed

5 files changed

+99
-43
lines changed

plugin/src/main/java/org/docstr/gwt/AbstractBaseTask.java

Lines changed: 72 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.stream.Collectors;
99
import javax.inject.Inject;
1010
import org.gradle.api.GradleException;
11+
import org.gradle.api.Project;
1112
import org.gradle.api.file.ConfigurableFileCollection;
1213
import org.gradle.api.file.DirectoryProperty;
1314
import 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
}

plugin/src/main/java/org/docstr/gwt/GwtCompileConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,11 @@ public void execute(GwtCompileTask task) {
341341
throw new GradleException(
342342
"gwtCompile failed: 'modules' property is required. Please specify at least one GWT module in the gwt { ... } block.");
343343
}
344+
345+
// Configure classpath and arguments during configuration phase for Configuration Cache compatibility
346+
task.configureClasspath(project);
347+
task.configureArgs();
348+
task.configureCompileArgs();
344349
}
345350

346351
/**

plugin/src/main/java/org/docstr/gwt/GwtCompileTask.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@ public GwtCompileTask(ObjectFactory objects) {
101101
// Set GWT compiler as the main class
102102
getMainClass().set(COMPILER_CLASS);
103103

104-
// This task will depend on the compileJava task automatically
104+
// This task will depend on the compileJava and processResources tasks automatically
105105
dependsOn(getProject().getTasks().withType(JavaCompile.class)
106106
.matching(task ->
107107
!task.getName().toLowerCase().contains("test")));
108+
dependsOn(getProject().getTasks().named("processResources"));
108109
}
109110

110111
/**
@@ -224,8 +225,10 @@ public DirectoryProperty getSaveSourceOutput() {
224225
return saveSourceOutput;
225226
}
226227

227-
@Override
228-
public void exec() {
228+
/**
229+
* Configure task-specific arguments during configuration phase.
230+
*/
231+
public void configureCompileArgs() {
229232
if (getClosureFormattedOutput().isPresent()) {
230233
if (getClosureFormattedOutput().get()) {
231234
args("-XclosureFormattedOutput");
@@ -308,8 +311,11 @@ public void exec() {
308311
args("-saveSourceOutput",
309312
getSaveSourceOutput().get().getAsFile().getPath());
310313
}
314+
}
311315

312-
getProject().getLogger()
316+
@Override
317+
public void exec() {
318+
getLogger()
313319
.info("inputs: {}", getInputs().getFiles().getAsPath());
314320
super.exec();
315321
}

plugin/src/main/java/org/docstr/gwt/GwtDevModeConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.gradle.api.Action;
1919
import org.gradle.api.GradleException;
20+
import org.gradle.api.Project;
2021

2122
/**
2223
* Configures the GWT dev mode task.
@@ -35,6 +36,7 @@ public GwtDevModeConfig(GwtPluginExtension extension) {
3536

3637
@Override
3738
public void execute(GwtDevModeTask task) {
39+
Project project = task.getProject();
3840
if (extension.getDevMode().getMinHeapSize().isPresent()) {
3941
task.setMinHeapSize(extension.getDevMode().getMinHeapSize().get());
4042
} else {
@@ -173,5 +175,9 @@ public void execute(GwtDevModeTask task) {
173175
throw new GradleException(
174176
"gwtDevMode failed: 'modules' property is required. Please specify at least one GWT module in the gwt { ... } block.");
175177
}
178+
179+
// Configure classpath and arguments during configuration phase for Configuration Cache compatibility
180+
task.configureClasspath(project);
181+
task.configureArgs();
176182
}
177183
}

plugin/src/main/java/org/docstr/gwt/GwtSuperDevConfig.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.gradle.api.Action;
1919
import org.gradle.api.GradleException;
20+
import org.gradle.api.Project;
2021

2122
/**
2223
* Configures the GWT super dev task.
@@ -36,6 +37,7 @@ public GwtSuperDevConfig(GwtPluginExtension extension) {
3637

3738
@Override
3839
public void execute(GwtSuperDevTask task) {
40+
Project project = task.getProject();
3941
if (extension.getSuperDev().getMinHeapSize().isPresent()) {
4042
task.setMinHeapSize(extension.getSuperDev().getMinHeapSize().get());
4143
} else {
@@ -157,5 +159,9 @@ public void execute(GwtSuperDevTask task) {
157159
throw new GradleException(
158160
"gwtSuperDev failed: 'modules' property is required. Please specify at least one GWT module in the gwt { ... } block.");
159161
}
162+
163+
// Configure classpath and arguments during configuration phase for Configuration Cache compatibility
164+
task.configureClasspath(project);
165+
task.configureArgs();
160166
}
161167
}

0 commit comments

Comments
 (0)