Skip to content

Commit e8c6d92

Browse files
authored
[Feature]: Improved caching (#191)
1 parent a5c57e3 commit e8c6d92

File tree

57 files changed

+2264
-473
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2264
-473
lines changed

common/src/main/java/net/neoforged/gradle/common/CommonProjectPlugin.java

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import net.neoforged.gradle.common.runtime.definition.CommonRuntimeDefinition;
1212
import net.neoforged.gradle.common.runtime.extensions.RuntimesExtension;
1313
import net.neoforged.gradle.common.runtime.naming.OfficialNamingChannelConfigurator;
14+
import net.neoforged.gradle.common.tasks.CleanCache;
1415
import net.neoforged.gradle.common.tasks.DisplayMappingsLicenseTask;
1516
import net.neoforged.gradle.common.util.ProjectUtils;
1617
import net.neoforged.gradle.common.util.SourceSetUtils;
@@ -59,6 +60,7 @@ public class CommonProjectPlugin implements Plugin<Project> {
5960

6061
public static final String ASSETS_SERVICE = "ng_assets";
6162
public static final String LIBRARIES_SERVICE = "ng_libraries";
63+
public static final String EXECUTE_SERVICE = "ng_execute";
6264
public static final String ACCESS_TRANSFORMER_ELEMENTS_CONFIGURATION = "accessTransformerElements";
6365
public static final String ACCESS_TRANSFORMER_API_CONFIGURATION = "accessTransformerApi";
6466
public static final String ACCESS_TRANSFORMER_CONFIGURATION = "accessTransformer";
@@ -72,8 +74,9 @@ public void apply(Project project) {
7274
project.getPluginManager().apply(JavaPlugin.class);
7375

7476
//Register the services
75-
CentralCacheService.register(project, ASSETS_SERVICE);
76-
CentralCacheService.register(project, LIBRARIES_SERVICE);
77+
CentralCacheService.register(project, ASSETS_SERVICE, true);
78+
CentralCacheService.register(project, LIBRARIES_SERVICE, true);
79+
CentralCacheService.register(project, EXECUTE_SERVICE, false);
7780

7881
// Apply both the idea and eclipse IDE plugins
7982
project.getPluginManager().apply(IdeaPlugin.class);
@@ -136,8 +139,11 @@ public void apply(Project project) {
136139

137140
IdeRunIntegrationManager.getInstance().setup(project);
138141

142+
final TaskProvider<?> cleanCache = project.getTasks().register("cleanCache", CleanCache.class);
143+
139144
project.getTasks().named("clean", Delete.class, delete -> {
140145
delete.delete(configurationData.getLocation());
146+
delete.dependsOn(cleanCache);
141147
});
142148

143149
//Needs to be before after evaluate
@@ -174,17 +180,22 @@ private void configureSourceSetConventions(Project project, Conventions conventi
174180
}
175181

176182
ProjectUtils.afterEvaluate(project, () -> {
177-
project.getExtensions().configure(RunsConstants.Extensions.RUNS, (Action<NamedDomainObjectContainer<Run>>) runs -> runs.configureEach(run -> {
178-
if (sourceSets.getShouldMainSourceSetBeAutomaticallyAddedToRuns().get()) {
179-
//We always register main
180-
run.getModSources().add(project.getExtensions().getByType(SourceSetContainer.class).getByName("main"));
181-
}
183+
project.getExtensions().configure(RunsConstants.Extensions.RUNS, (Action<NamedDomainObjectContainer<Run>>) runs -> {
184+
runs.configureEach(run -> {
185+
if (sourceSets.getShouldMainSourceSetBeAutomaticallyAddedToRuns().get()) {
186+
//We always register main
187+
run.getModSources().add(project.getExtensions().getByType(SourceSetContainer.class).getByName("main"));
188+
}
182189

183-
if (sourceSets.getShouldSourceSetsLocalRunRuntimesBeAutomaticallyAddedToRuns().get() && configurations.getIsEnabled().get())
184-
run.getModSources().get().forEach(sourceSet -> {
185-
run.getDependencies().get().getRuntime().add(project.getConfigurations().getByName(ConfigurationUtils.getSourceSetName(sourceSet, configurations.getRunRuntimeConfigurationPostFix().get())));
186-
});
187-
}));
190+
if (sourceSets.getShouldSourceSetsLocalRunRuntimesBeAutomaticallyAddedToRuns().get() && configurations.getIsEnabled().get()) {
191+
run.getModSources().get().forEach(sourceSet -> {
192+
if (project.getConfigurations().findByName(ConfigurationUtils.getSourceSetName(sourceSet, configurations.getRunRuntimeConfigurationPostFix().get())) != null) {
193+
run.getDependencies().get().getRuntime().add(project.getConfigurations().getByName(ConfigurationUtils.getSourceSetName(sourceSet, configurations.getRunRuntimeConfigurationPostFix().get())));
194+
}
195+
});
196+
}
197+
});
198+
});
188199
});
189200

190201
}

0 commit comments

Comments
 (0)