We are using spring boot 3.0.2 (same behavior in 3.0.1) as parent and derived maven plugin io.github.git-commit-id:git-commit-id-maven-plugin. We also use org.apache.maven.plugins:maven-jar-plugin that we configure custom manifestSections and add some extra info from git plugin. In our recent changes we added git commit message in MANIFEST, but then we faced the following error after a few commits.
INFO] --- spring-boot-maven-plugin:3.0.2:repackage (repackage) @ my-app ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.736 s
[INFO] Finished at: 2023-01-23T20:31:17+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.2:repackage (repackage) on project my-app: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:3.0.2:repackage failed: Error reading archive file: invalid manifest format (line 27) -> [Help 1]
After a few trial and error, I found that if commit message contains the slash (/) character in second line, then we got the above error. If / exist in first line and commit msg is only one line, then no problem occurs.
I have not checked for other problematic chars or if / exist only in third line.
Example plugins of pom.xml
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<manifestSections>
<manifestSection>
<name>Additional Info</name>
<manifestEntries>
<!-- ...more params... -->
<Git-Commit-Message-Full>${git.commit.message.full}</Git-Commit-Message-Full>
<!-- ...more params... -->
</manifestEntries>
</manifestSection>
</manifestSections>
</archive>
</configuration>
</plugin>
Comment From: scottfrederick
The invalid manifest format error comes from the java.util.jar.Manifest class when the Spring Boot Maven plugin calls it to read the manifest from the plain jar file that Maven builds. This can happen when a manifest file has a blank line, and maybe in some other situations.
@qiozas Please share the META-INF/MANIFEST.MF file that Maven generates so we can see what might be in there that java.util.jar.Manifest doesn't like. Also run the build with the -e option to show the stacktrace when the error occurs and add that in a comment, so we can confirm that it is the java.util.jar.Manifest class that is detecting the problem.
Comment From: qiozas
Last dummy commit msg is:
asdf asdf
sfadsf / sdfgfd
MANIFEST.MF
Manifest-Version: 1.0
Created-By: Maven JAR Plugin 3.3.0
Build-Jdk-Spec: 17
Implementation-Title: my-app
Implementation-Version: 0.0.1-SNAPSHOT
Name: Additional Info
Implementation-Version: 0.0.1-SNAPSHOT
Git-Commit-Id-Abbrev: 3c73038
Java-Vendor: Eclipse Adoptium
Specification-Title: my-app
Implementation-URL: null
Build-By: qiozas
Build-Timestamp: 2023-01-24 16:25:33 UTC
Implementation-Vendor: null
Java-VM-Version: 17.0.3+7
Git-Commit-Time: 2023-01-23T20:32:20+0200
OS-Name: Linux
Git-Branch: develop
Git-Commit-User-Name: My Name
Specification-Vendor: null
Git-Commit-Id: 3c7303860efffb40e8d89d49197d912358e142ad
Implementation-Title: my-app
Specification-Version: 0.0.1-SNAPSHOT
Git-Commit-Message-Full: asdf asdf
sfadsf / sdfgfd
Comment From: qiozas
Partial exception trace when running mvn -e clean package:
...
[INFO] --- spring-boot-maven-plugin:3.0.2:repackage (repackage) @ my-app ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.880 s
[INFO] Finished at: 2023-01-24T18:31:16+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.2:repackage (repackage) on project my-app: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:3.0.2:repackage failed: Error reading archive file: invalid header field (line 26) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.2:repackage (repackage) on project my-app: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:3.0.2:repackage failed: Error reading archive file
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:306)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:211)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:165)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:157)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:121)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:127)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:3.0.2:repackage failed: Error reading archive file
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:148)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:301)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:211)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:165)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:157)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:121)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:127)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.lang.IllegalStateException: Error reading archive file
at org.springframework.boot.loader.tools.Packager.isAlreadyPackaged (Packager.java:183)
at org.springframework.boot.loader.tools.Packager.isAlreadyPackaged (Packager.java:174)
at org.springframework.boot.loader.tools.Repackager.repackage (Repackager.java:107)
at org.springframework.boot.maven.RepackageMojo.repackage (RepackageMojo.java:216)
at org.springframework.boot.maven.RepackageMojo.execute (RepackageMojo.java:206)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:301)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:211)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:165)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:157)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:121)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:127)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
Caused by: java.io.IOException: invalid header field (line 26)
at java.util.jar.Attributes.read (Attributes.java:406)
at java.util.jar.Manifest.read (Manifest.java:347)
at java.util.jar.Manifest.<init> (Manifest.java:100)
at java.util.jar.JarFile.getManifestFromReference (JarFile.java:430)
at java.util.jar.JarFile.getManifest (JarFile.java:407)
at org.springframework.boot.loader.tools.Packager.isAlreadyPackaged (Packager.java:179)
at org.springframework.boot.loader.tools.Packager.isAlreadyPackaged (Packager.java:174)
at org.springframework.boot.loader.tools.Repackager.repackage (Repackager.java:107)
at org.springframework.boot.maven.RepackageMojo.repackage (RepackageMojo.java:216)
at org.springframework.boot.maven.RepackageMojo.execute (RepackageMojo.java:206)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
at org.apache.maven.lifecycle.internal.MojoExecutor.doExecute (MojoExecutor.java:301)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:211)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:165)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:157)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:121)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:127)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:294)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:960)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:293)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:196)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:77)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:568)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
[ERROR]
...
Comment From: scottfrederick
@qiozas Thanks very much for the additional information. As with my tests, the error is coming from a class in java.util.jar, which considers the manifest invalid. In this case, it expects the value on each line to be a key/value pair separated by a : character, and the second line of the commit message containing sfadsf / sdfgfd does not fit this pattern.
This is out of Spring Boot's control, and will need to be addressed by the io.github.git-commit-id:git-commit-id-maven-plugin project that is adding the entries. There is a similar issue regarding invalid manifest entries in the issue tracker for that project. You might be able to use something similar to the suggestion given in that issue, or file a new issue with the project.
Comment From: qiozas
@scottfrederick thanks for your time, I agree with your perspective.