Skip to content

Commit 08d4c29

Browse files
committed
Add configuration cache tests and improve runtime output handling
1 parent a17eff2 commit 08d4c29

4 files changed

Lines changed: 94 additions & 3 deletions

File tree

.github/workflows/test-prs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ jobs:
9696
runs-on: "${{ matrix.os }}-latest"
9797
needs: [setup, set-gradle-version]
9898
strategy:
99-
max-parallel: 15
99+
max-parallel: 8
100100
fail-fast: false
101101
matrix:
102102
test: ${{ fromJSON(needs.setup.outputs.tests-to-run) }}

common/src/main/java/net/neoforged/gradle/common/runtime/extensions/CommonRuntimeExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public static Configuration extractVersionJsonLibraries(final @NotNull Project p
150150
final FileCollection recompileDependencies,
151151
final Consumer<TaskProvider<? extends Runtime>> configure)
152152
{
153-
final Provider<? extends FileTree> recompileSourceFileTree = recompileInput.flatMap(WithOutput::getOutputAsTree);
153+
final Provider<? extends FileTree> recompileSourceFileTree = recompileInput.flatMap(WithOutput::getOutputAsTree);
154154

155155
final CommonRuntimeSpecification spec = definition.getSpecification();
156156
// Consider user-settings

common/src/main/java/net/neoforged/gradle/common/runtime/tasks/DefaultRuntime.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ protected void buildRuntimeArguments(final Map<String, Provider<String>> argumen
9797
@Override
9898
public Provider<? extends FileTree> getOutputAsTree()
9999
{
100-
return getOutput().map(it -> getArchiveOperations().zipTree(it));
100+
var archiveOperations = getArchiveOperations();
101+
return getOutput().map(archiveOperations::zipTree);
101102
}
102103
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package net.neoforged.gradle.userdev
2+
3+
import net.neoforged.trainingwheels.gradle.functional.BuilderBasedTestSpecification
4+
import org.gradle.testkit.runner.TaskOutcome
5+
6+
class ConfigurationCacheTests extends BuilderBasedTestSpecification {
7+
8+
private static final String NEOFORM_VERSION = "26.1-snapshot-1-3"
9+
10+
@Override
11+
protected void configurePluginUnderTest() {
12+
pluginUnderTest = "net.neoforged.gradle.neoform";
13+
injectIntoAllProject = true;
14+
}
15+
16+
def "compile_supports_configuration_cache_build"() {
17+
given:
18+
def project = create("compile_supports_configuration_cache_build", {
19+
it.build("""
20+
java.toolchain.languageVersion = JavaLanguageVersion.of(25)
21+
22+
dependencies {
23+
implementation 'net.minecraft:neoform_joined:${NEOFORM_VERSION}'
24+
}
25+
""")
26+
it.withToolchains()
27+
it.withGlobalCacheDirectory(tempDir)
28+
it.enableLocalBuildCache()
29+
it.enableConfigurationCache()
30+
})
31+
32+
when:
33+
def run = project.run {
34+
it.tasks('compileJava')
35+
}
36+
37+
then:
38+
run.task(':compileJava').outcome == TaskOutcome.NO_SOURCE
39+
}
40+
41+
def "compile_supports_configuration_cache_build_and_is_reused"() {
42+
given:
43+
def project = create("compile_supports_configuration_cache_build_and_is_reused", {
44+
it.build("""
45+
java.toolchain.languageVersion = JavaLanguageVersion.of(25)
46+
47+
dependencies {
48+
implementation 'net.minecraft:neoform_joined:${NEOFORM_VERSION}'
49+
}
50+
""")
51+
it.file("src/main/java/net/neoforged/gradle/userdev/ConfigurationCacheTests.java", """
52+
package net.neoforged.gradle.userdev;
53+
54+
import net.minecraft.client.Minecraft;
55+
56+
public class ConfigurationCacheTests {
57+
public static void main(String[] args) {
58+
System.out.println(Minecraft.getInstance().getClass().toString());
59+
}
60+
}
61+
""")
62+
it.withToolchains()
63+
it.withGlobalCacheDirectory(tempDir)
64+
it.enableLocalBuildCache()
65+
it.enableConfigurationCache()
66+
})
67+
68+
when:
69+
def run = project.run {
70+
it.tasks('compileJava')
71+
}
72+
73+
and:
74+
def secondaryRun = project.run {
75+
it.tasks('compileJava')
76+
}
77+
78+
and:
79+
def thirdRun = project.run {
80+
it.tasks('compileJava')
81+
}
82+
83+
then:
84+
thirdRun.output.contains('Reusing configuration cache.')
85+
run.task(':neoFormDecompile').outcome == TaskOutcome.SUCCESS
86+
run.task(':compileJava').outcome == TaskOutcome.SUCCESS
87+
thirdRun.task(':neoFormDecompile').outcome == TaskOutcome.FROM_CACHE
88+
thirdRun.task(':compileJava').outcome == TaskOutcome.FROM_CACHE
89+
}
90+
}

0 commit comments

Comments
 (0)