诊断可重现的构建问题

在检查 Reproducible Build 时,您可能会发现当前的构建输出与参考不一样:

$ mvn -Papache-release clean verify -Dgpg.skip artifact:compare
[INFO] Scanning for projects...
...
[INFO] --- maven-artifact-plugin:3.2.0:buildinfo (default-cli) @ doxia-module-markdown ---
[INFO] Saved aggregate info on build to /tmp/doxia-1.9.1/doxia-modules/doxia-module-markdown/target/doxia-module-markdown-1.9.1.buildinfo
[INFO] Checking against reference build from central...
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/doxia/doxia-module-markdown/1.9.1/doxia-module-markdown-1.9.1.buildinfo
[WARNING] Reference buildinfo file not found: it will be generated from downloaded reference artifacts
[INFO] Reference build java.version: 1.8 (from MANIFEST.MF Build-Jdk-Spec)
[INFO] Reference build java.version: 1.8 (from MANIFEST.MF Build-Jdk-Spec)
[ERROR] Current build java.version: 1.7 (from MANIFEST.MF Build-Jdk-Spec)
[INFO] Reference build os.name: Unix (from pom.properties newline)
[INFO] Minimal buildinfo generated from downloaded artifacts: /tmp/doxia-1.9.1/target/reference/doxia-module-markdown-1.9.1.buildinfo
[WARNING] size mismatch doxia-logging-api-1.9.1.jar: investigate with diffoscope target/reference/doxia-logging-api-1.9.1.jar doxia-logging-api/target/doxia-logging-api-1.9.1.jar
...
[WARNING] size mismatch doxia-module-markdown-1.9.1.jar: investigate with diffoscope target/reference/doxia-module-markdown-1.9.1.jar doxia-modules/doxia-module-markdown/target/doxia-module-markdown-1.9.1.jar
[WARNING] Reproducible Build output summary: 39 files ok, 18 different
[WARNING] see diff target/reference/doxia-module-markdown-1.9.1.buildinfo doxia-modules/doxia-module-markdown/target/doxia-module-markdown-1.9.1.buildinfo
[WARNING] see also https://maven.apache.org/guides/mini/guide-reproducible-builds.html
[INFO] Reproducible Build output comparison saved to /tmp/doxia-1.9.1/doxia-modules/doxia-module-markdown/target/doxia-module-markdown-1.9.1.buildcompare
[INFO] Aggregate buildcompare copied to /tmp/doxia-1.9.1/target/doxia-1.9.1.buildcompare
...

提供多个有趣的部分:

  • 摘要:[警告] Reproducible Build 输出摘要:39 个文件正常,18 个不同
  • 参考构建环境的关键信息:
    [INFO] Reference build java.version: 1.8 (from MANIFEST.MF Build-Jdk-Spec)
    [INFO] Reference build os.name: Unix (from pom.properties newline)
    这是关键要求(JDK主要版本和操作系统)为构建环境重现参考构建
  • 最终与当前构建环境不匹配:
    [错误] 当前构建 java.version:1.7(来自 MANIFEST.MF Build-Jdk-Spec)
  • 在与参考不同的每个工件上,提供了一个命令来使用diffoscope 工具调查差异,这是一个在档案(jar,zip,tar,...)内工作的 diff 工具:
    只需复制粘贴提供的命令,如diffoscope target/reference/doxia-logging -api-1.9.1.jar doxia-logging-api/target/doxia-logging-api-1.9.1.jar你会看到差异在哪里:
    $ diffoscope target/reference/doxia-logging-api-1.9.1.jar doxia-logging-api/target/doxia-logging-api-1.9.1.jar
    --- target/reference/doxia-logging-api-1.9.1.jar
    +++ doxia-logging-api/target/doxia-logging-api-1.9.1.jar
    ├── zipinfo /dev/stdin
    │ @@ -1,8 +1,8 @@
    │ -Zip file size: 11516 bytes, number of entries: 19
    │ +Zip file size: 11497 bytes, number of entries: 19
    │  -rw-r--r--  2.0 unx      337 b- defN 20-Feb-13 21:11 META-INF/MANIFEST.MF
    │  drwxr-xr-x  2.0 unx        0 b- stor 20-Feb-13 21:11 META-INF/
    │  drwxr-xr-x  2.0 unx        0 b- stor 20-Feb-13 21:11 org/
    │  drwxr-xr-x  2.0 unx        0 b- stor 20-Feb-13 21:11 org/apache/
    │  drwxr-xr-x  2.0 unx        0 b- stor 20-Feb-13 21:11 org/apache/maven/
    │  drwxr-xr-x  2.0 unx        0 b- stor 20-Feb-13 21:11 org/apache/maven/doxia/
    │  drwxr-xr-x  2.0 unx        0 b- stor 20-Feb-13 21:11 org/apache/maven/doxia/logging/
    │ @@ -11,11 +11,11 @@
    │  drwxr-xr-x  2.0 unx        0 b- stor 20-Feb-13 21:11 META-INF/maven/org.apache.maven.doxia/doxia-logging-api/
    │  -rw-r--r--  2.0 unx     1641 b- defN 20-Feb-13 21:11 META-INF/DEPENDENCIES
    │  -rw-r--r--  2.0 unx    11358 b- defN 20-Feb-13 21:11 META-INF/LICENSE
    │  -rw-r--r--  2.0 unx      177 b- defN 20-Feb-13 21:11 META-INF/NOTICE
    │  -rw-r--r--  2.0 unx      716 b- defN 20-Feb-13 21:11 org/apache/maven/doxia/logging/Log.class
    │  -rw-r--r--  2.0 unx      198 b- defN 20-Feb-13 21:11 org/apache/maven/doxia/logging/LogEnabled.class
    │  -rw-r--r--  2.0 unx     2840 b- defN 20-Feb-13 21:11 org/apache/maven/doxia/logging/PlexusLoggerWrapper.class
    │ --rw-r--r--  2.0 unx     4208 b- defN 20-Feb-13 21:11 org/apache/maven/doxia/logging/SystemStreamLog.class
    │ +-rw-r--r--  2.0 unx     4192 b- defN 20-Feb-13 21:11 org/apache/maven/doxia/logging/SystemStreamLog.class
    │  -rw-r--r--  2.0 unx     1539 b- defN 20-Feb-13 21:11 META-INF/maven/org.apache.maven.doxia/doxia-logging-api/pom.xml
    │  -rw-r--r--  2.0 unx       74 b- defN 20-Feb-13 21:11 META-INF/maven/org.apache.maven.doxia/doxia-logging-api/pom.properties
    │ -19 files, 23088 bytes uncompressed, 8842 bytes compressed:  61.7%
    │ +19 files, 23072 bytes uncompressed, 8823 bytes compressed:  61.8%
    ├── META-INF/MANIFEST.MF
    │ @@ -1,10 +1,10 @@
    │  Manifest-Version: 1.0
    │ +Implementation-Vendor: The Apache Software Foundation
    │  Implementation-Title: Doxia :: Logging API
    │  Implementation-Version: 1.9.1
    │ +Build-Jdk-Spec: 1.7
    │  Specification-Vendor: The Apache Software Foundation
    │ -Specification-Title: Doxia :: Logging API
    │ -Build-Jdk-Spec: 1.8
    │  Created-By: Maven Jar Plugin 3.2.0
    │ +Specification-Title: Doxia :: Logging API
    │  Specification-Version: 1.9
    │ -Implementation-Vendor: The Apache Software Foundation
    ├── org/apache/maven/doxia/logging/PlexusLoggerWrapper.class
    ...

在此示例中,参考构建是使用 JDK 8 完成的(参见│ -Build-Jdk-Spec: 1.8),但当前构建是使用 JDK 7 完成的(参见│ +Build-Jdk-Spec: 1.7):这解释了两者的区别在每个 .jar 文件的META-INF/MANIFEST.MF的内容中,以及.class文件中的一些字节码的内容中。

修复一般环境问题后,对于每个剩余问题,您必须查找生成内容的 Maven 插件,并查看是否有生成可重现输出的插件更新:请参阅/guides/mini的插件表/guide-reproducible-builds.html用于初始列表。