I am not able to deploy to cloud foundry using cf push after upgrading to spring-boot 2.6.2.

The error is zip: not a valid zip file

A workaround that kind-a works for now is to downgrade the version of the spring-boot-maven-plugin to 2.5.8 then cf command line tool accepts the produced fat jar. The difference is that now I get different: Spring-Boot-Version manifest entry and spring-boot-jarmode-layertools jar in BOOT-INF/lib is 2.5.8 (everything else starting with spring-boot-* is still on 2.6.2)

I do not care much about the first diff, but I am not sure if having spring-boot-jarmode-layertools for 2.5 would cause any issues (if its not used in case of CF deployment can I easily exclude it?)

Found the same issue on SO https://stackoverflow.com/questions/70475420/unable-to-cf-push-the-spring-boot-2-6-1-app-giving-zip-not-a-valid-zip-file

Comment From: wilkinsona

We have a number of Spring Boot 2.6.x applications that are running on CloudFoundry, including http://spring.io so there must be something different in your situation. Can you please provide some more information about the failure and the versions of CF and the java buildpack that are involved (the complete logs of cf push could be useful for this).

Comment From: tsachev

This is the output of the cf push command

$ cf push -f manifests\manifest-perf.yml  
Pushing from manifest to org ******* / space ******* as *******...
Using manifest file manifests\manifest-perf.yml
Getting app info...
zip: not a valid zip file
FAILED

I suspect that this error happens on the client side before uploading the zip- because I remember fancy spring boot zip usage caused problems with cf client some time ago. I believe it was related with the executable flag and cf client's zip library.

And here is the cf client version (I know it is pretty dated, but that is what I am dealing with)

$ cf -v
cf version 6.42.0+0cba12168.2019-01-10

Comment From: scottfrederick

There was a change in Spring Boot 2.6 that corrects the jar file central directory when a launch script is included the jar file. It's possible this could be causing the cf CLI to treat the jar file differently than a jar file created with an earlier Spring Boot version.

I suspect that this error happens on the client side before uploading the zip- because I remember fancy spring boot zip usage caused problems with cf client some time ago. I believe it was related with the executable flag and cf client's zip library.

@tsachev Are you creating an executable jar file that includes a launch script, and if so can you test to see what the cf CLI does if the jar file is not executable?

Comment From: octmueller

Having the same issue with spring-boot-maven-plugin >= 2.6.0 Tried cf client versions cf version 7.0.1+fb3f929c2.2020-06-24 cf version 8.1.0+034d929d7.2022-01-03

Get follwing message when executing "cf push" zip: not a valid zip file FAILED

Comment From: tsachev

@tsachev Are you creating an executable jar file that includes a launch script, and if so can you test to see what the cf CLI does if the jar file is not executable?

@scottfrederick When I set false in maven plugin configuration for the repackage execution the zip is correctly handled by the cf client. My issue is resolved.

I know that executable didn't not work with cf, but for some reason (custom parent pom and plugin configurations in several layers of the pom inheritance) my configuration was not applied. It works with 2.5.8 which surprises me (I missed that this was fixed at some point), but it turns out it strikes again with 2.6

Comment From: scottfrederick

@octmueller I'll ask you the same question - are you creating an executable jar file that includes a launch script, and if so can you test to see what the cf CLI does if the jar file is not executable?

Comment From: octmueller

Yes, I was creating an executable. I added the following to my pom.xml and now it works

<pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>repackage</id>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                    <configuration>
                        <executable>false</executable>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</pluginManagement>

Thanks!

Comment From: scottfrederick

I'm glad to hear you've been able to make this work without the launch script enabled. cf push should work either way, as the jar file generated by Spring Boot is valid now that the central directory is correct. If anyone has a need to cf push with the launch script enabled, they should file an issue with the cf CLI so that team can investigate why they don't recognize the jar file as a valid zip file.

Comment From: snbeynon

For anyone landing here with the same issue, I had this problem on boot 2.7 but it went away when changing the CF manifest to use host & domain instead of routes. Probably using an old CF CLI too. Definitely not a spring-boot issue.