Skip to content

Commit

Permalink
build.xml: Make MANIFEST.MF friendlier to reproducible builds
Browse files Browse the repository at this point in the history
Override the values of Created-By and Ant-Version entries to make
reproducible builds easier. This can be disabled by setting
manifest_cleanup=false.

The JAR specification gives an impression that the Created-By
entry refers to the version and vendor of the Java implementation.
Ant's default output conforms to that. On the other hand, Maven
and its plugins use strings that refer to Maven or plugin names
and versions. Thus, in the real-world the Created-By entry can
refer to different things.
  • Loading branch information
Larhzu committed Jul 29, 2024
1 parent d18a12a commit 2103742
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
6 changes: 6 additions & 0 deletions build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ sourcever = 8
sourcever9 = 9
java8only = false

# If true, the entries Created-By and Ant-Version in MANIFEST.MF will be
# set to more stable values to make reproducible builds easier.
manifest_cleanup = true

# If true, javadoc is called with en_US locale to force the headings and
# such strings from javadoc to be in English, independent of the system
# language settings. This helps with reproducible builds.
Expand All @@ -33,6 +37,8 @@ dist_dir = ${build_dir}/dist
dist_file = ${dist_dir}/xz-java-${version}.zip
classes_dir = ${build_dir}/classes
classes9_dir = ${build_dir}/classes9
manifest_dir = ${build_dir}/manifest
manifest_base = ${manifest_dir}/base.mf
jar_dir = ${build_dir}/jar
doc_dir = ${build_dir}/doc
pom_dir = ${build_dir}/pom
Expand Down
32 changes: 28 additions & 4 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,32 @@
</javac>
</target>

<target name="jar" depends="compile"
<target name="manifest">
<mkdir dir="${manifest_dir}"/>

<manifest file="${manifest_base}">
<!-- The exact Ant version used for the build shouldn't make
any difference in the produced files, so don't let it
affect the manifest either. -->
<attribute name="Ant-Version" value="Intentionally omitted"
if:true="${manifest_cleanup}"/>

<!-- Compiler output varies between major OpenJDK releases but
it can be stable between minor releases, thus the minor
version information can be annoying for reproducible builds.
java.specification.version contains only the major version.
It's already used by Maven Archiver for Build-Jdk-Spec. -->
<attribute name="Created-By" value="${java.specification.version}"
if:true="${manifest_cleanup}"/>
</manifest>
</target>

<target name="jar" depends="compile, manifest"
description="Creates JAR packages">
<mkdir dir="${jar_dir}"/>

<jar destfile="${jar_dir}/xz.jar" modificationtime="${timestamp}">
<jar destfile="${jar_dir}/xz.jar" modificationtime="${timestamp}"
manifest="${manifest_base}">
<fileset dir="${classes_dir}" includes="org/tukaani/xz/**"/>
<zipfileset prefix="META-INF/versions/9/" dir="${classes9_dir}"
unless:true="${java8only}"/>
Expand Down Expand Up @@ -104,6 +125,7 @@
<sequential>
<jar destfile="${jar_dir}/@{name}.jar"
modificationtime="${timestamp}"
manifest="${manifest_base}"
basedir="${classes_dir}"
includes="@{name}.class">
<manifest>
Expand Down Expand Up @@ -136,7 +158,7 @@
</copy>
</target>

<target name="maven" depends="pom, doc, jar"
<target name="maven" depends="pom, manifest, doc, jar"
description="Creates POM and JAR files for a Maven repository">
<mkdir dir="${maven_dir}"/>

Expand All @@ -148,10 +170,12 @@

<jar destfile="${maven_dir}/xz-${version}-javadoc.jar"
modificationtime="${timestamp}"
manifest="${manifest_base}"
basedir="${doc_dir}"/>

<jar destfile="${maven_dir}/xz-${version}-sources.jar"
modificationtime="${timestamp}">
modificationtime="${timestamp}"
manifest="${manifest_base}">
<fileset dir="${src_dir}" includes="org/tukaani/xz/**"/>
<zipfileset prefix="META-INF/versions/9/" dir="${src9_dir}"/>
</jar>
Expand Down

0 comments on commit 2103742

Please sign in to comment.