Skip to content

Commit 6154f2b

Browse files
authored
Add Maven recipes for reproducible builds (#7541)
* Add Maven recipes for reproducible builds (#7476) Introduces a `ReproducibleBuilds` composite that sets `project.build.outputTimestamp`, enforces UTF-8 source/reporting encoding, and upgrades Apache Maven plugins to versions that honor the output timestamp. Existing values are preserved. * Inline trivial wrapper recipes into ReproducibleBuilds composite Removes the standalone AddSourceEncodingProperty and UpgradePluginVersionsForReproducibleBuilds wrappers and inlines their content directly in ReproducibleBuilds. ReproducibleBuildsTest still exercises the full behavior end-to-end. * Regenerate recipes.csv
1 parent 9337667 commit 6154f2b

5 files changed

Lines changed: 336 additions & 57 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright 2026 the original author or authors.
3+
* <p>
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* <p>
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
* <p>
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.openrewrite.maven.cleanup;
17+
18+
import lombok.EqualsAndHashCode;
19+
import lombok.Value;
20+
import org.jspecify.annotations.Nullable;
21+
import org.openrewrite.Option;
22+
import org.openrewrite.Recipe;
23+
import org.openrewrite.maven.AddProperty;
24+
25+
import java.util.List;
26+
27+
import static java.util.Collections.singletonList;
28+
29+
@Value
30+
@EqualsAndHashCode(callSuper = false)
31+
public class AddProjectBuildOutputTimestamp extends Recipe {
32+
33+
@Option(displayName = "Timestamp",
34+
description = "ISO 8601 timestamp, integer seconds since the epoch, or property reference such as " +
35+
"`${git.commit.author.time}`. Defaults to `1980-01-01T00:00:00Z`, the earliest value " +
36+
"the ZIP format can represent.",
37+
example = "2024-01-01T00:00:00Z",
38+
required = false)
39+
@Nullable
40+
String timestamp;
41+
42+
@Override
43+
public String getDisplayName() {
44+
return "Add `project.build.outputTimestamp` for reproducible builds";
45+
}
46+
47+
@Override
48+
public String getDescription() {
49+
return "Adds the `project.build.outputTimestamp` property, which Maven uses to make build outputs " +
50+
"reproducible by stamping archive entries with a fixed timestamp instead of the current time. " +
51+
"An existing value is preserved. " +
52+
"See [Configuring for Reproducible Builds](https://maven.apache.org/guides/mini/guide-reproducible-builds.html).";
53+
}
54+
55+
@Override
56+
public List<Recipe> getRecipeList() {
57+
return singletonList(new AddProperty(
58+
"project.build.outputTimestamp",
59+
timestamp == null ? "1980-01-01T00:00:00Z" : timestamp,
60+
true,
61+
false));
62+
}
63+
}

rewrite-maven/src/main/resources/META-INF/rewrite/maven.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,27 @@ recipeList:
158158
filePattern: "**/mvnw.cmd"
159159
- org.openrewrite.DeleteSourceFiles:
160160
filePattern: "**/.mvn/wrapper/**"
161+
---
162+
type: specs.openrewrite.org/v1beta/recipe
163+
name: org.openrewrite.maven.ReproducibleBuilds
164+
displayName: Apache Maven reproducible builds
165+
description: >-
166+
Configure a Maven project for [reproducible builds](https://maven.apache.org/guides/mini/guide-reproducible-builds.html):
167+
pin dependency and plugin versions, set `project.build.outputTimestamp`, set explicit UTF-8 source encoding,
168+
and upgrade core plugins to versions that honor the output timestamp.
169+
recipeList:
170+
- org.openrewrite.maven.cleanup.ExplicitDependencyVersion
171+
- org.openrewrite.maven.cleanup.ExplicitPluginVersion
172+
- org.openrewrite.maven.UpgradePluginVersion:
173+
groupId: org.apache.maven.plugins
174+
artifactId: "maven-*-plugin"
175+
newVersion: latest.release
176+
- org.openrewrite.maven.AddProperty:
177+
key: project.build.sourceEncoding
178+
value: UTF-8
179+
preserveExistingValue: true
180+
- org.openrewrite.maven.AddProperty:
181+
key: project.reporting.outputEncoding
182+
value: UTF-8
183+
preserveExistingValue: true
184+
- org.openrewrite.maven.cleanup.AddProjectBuildOutputTimestamp

0 commit comments

Comments
 (0)