Skip to content

Commit 63038e0

Browse files
authored
Merge pull request #49009 from gsmet/sort-system-properties
Record system properties in order for build reproducibility
2 parents 545907d + 6319593 commit 63038e0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

core/deployment/src/main/java/io/quarkus/deployment/steps/MainClassBuildStep.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.lang.reflect.Modifier;
99
import java.util.ArrayList;
1010
import java.util.Collection;
11+
import java.util.Comparator;
1112
import java.util.HashMap;
1213
import java.util.List;
1314
import java.util.Map;
@@ -167,8 +168,10 @@ void build(List<StaticBytecodeRecorderBuildItem> staticInitTasks,
167168
mv.invokeStaticMethod(ofMethod(DisabledInitialContextManager.class, "register", void.class));
168169
}
169170

170-
//very first thing is to set system props (for build time)
171-
for (SystemPropertyBuildItem i : properties) {
171+
// very first thing is to set system props (for build time)
172+
// make sure we record the system properties in order for build reproducibility
173+
for (SystemPropertyBuildItem i : properties.stream().sorted(Comparator.comparing(SystemPropertyBuildItem::getKey))
174+
.toList()) {
172175
mv.invokeStaticMethod(ofMethod(System.class, "setProperty", String.class, String.class, String.class),
173176
mv.load(i.getKey()), mv.load(i.getValue()));
174177
}
@@ -219,9 +222,11 @@ void build(List<StaticBytecodeRecorderBuildItem> staticInitTasks,
219222
mv.setModifiers(Modifier.PROTECTED | Modifier.FINAL);
220223

221224
// Make sure we set properties in doStartup as well. This is necessary because setting them in the static-init
222-
// sets them at build-time, on the host JVM, while SVM has substitutions for System. get/ setProperty at
225+
// sets them at build-time, on the host JVM, while SVM has substitutions for System. get/setProperty at
223226
// run-time which will never see those properties unless we also set them at run-time.
224-
for (SystemPropertyBuildItem i : properties) {
227+
// make sure we record the system properties in order for build reproducibility
228+
for (SystemPropertyBuildItem i : properties.stream().sorted(Comparator.comparing(SystemPropertyBuildItem::getKey))
229+
.toList()) {
225230
mv.invokeStaticMethod(ofMethod(System.class, "setProperty", String.class, String.class, String.class),
226231
mv.load(i.getKey()), mv.load(i.getValue()));
227232
}

0 commit comments

Comments
 (0)