0

Anyone able to create an executable and non extractable jar using gradle with Spring boot bootJar task and with following versions:

Spring boot 2.6.7 (2.6.x), gradle 6.9.0, Spring Cloud 2021.0.0, Java version 8

Here is the reference which may help:

Spring Boot + Gradle: how to build executable jar

Other references will be helpful.

I am unable to create a non extractable and executable jar. Though Spring boot documentation says we can create non extractable jar. But it is creating an extractable jar (Executable jar).

I tried with bootJar task using launchScript, even though executable is created successfully, but the generated jar is extractable. But I am looking for non-extractable jar.

I was able to create non-extractable jar using SpringBoot version 2.5.13. But after upgrading to SpringBoot 2.6.7 (2.6.x), the generated jar file is extractable, however it is executable jar. Here I do not want the jar to be extractable like previously. Here are the options I tried.

bootJar {
    launchScript()
}

or

bootJar {
     archiveClassifier = 'boot'
}
Nagesh
  • 277
  • 6
  • 14
  • What do you mean with "non-extractable JAR"? Haven't heard that term in the Spring Boot context. – dunni May 30 '22 at 11:16
  • Please refer the SpringBoot documentation Section: Making an Archive Fully Executable https://docs.spring.io/spring-boot/docs/2.6.7/gradle-plugin/reference/htmlsingle/ – Nagesh May 30 '22 at 14:10
  • Ah, you mean like that one: https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html#deployment.installing where Spring Boot adds a bash script to the JAR, so that it's executable on Linux? That was only non-extractable, because the jar command cannot cope with it, so it wouldn't see that as a feature of the Spring Boot packaging mechanism – dunni May 30 '22 at 14:13
  • But Springboot 2.5.13 version, jar was not extractable. But after upgrading Springboot to 2.6.7(2.6.x), it is getting extracted. Upgraded version is not generating the jar same like previous, in this case. – Nagesh May 30 '22 at 14:19

1 Answers1

0

If you are referring to the functionality, where Spring Boot adds a bash script to the JAR, so that the JAR file is directly executable in Linux and can be added as a system service (like described here: https://docs.spring.io/spring-boot/docs/current/reference/html/deployment.html#deployment.installing), the Gradle configuration seems to have changed from older Spring Boot versions. The current documentation mentions the following snippet for Gradle:

tasks.named('bootJar') {
    launchScript()
}
dunni
  • 43,386
  • 10
  • 104
  • 99
  • Using launchScript() in gradle created Jar file which was directly excutable in Linux, in previous versions of Spring Boot also, for example Spring boot 2.5.13. But Jar was not extractable in previous versions. I am looking for both fully executable and non extractable jar, same like previous versions of SpringBoot 2.5.13. But this is not happenning in Springboot 2.6.7, I mean generated boot jar is extractable now. How do I restrict the jar to not extract now in Spring Boot 2.6.7. – Nagesh May 30 '22 at 14:41
  • 1
    Ok, but again the fact, that the JAR was not extractable, was not a feature of Spring Boot, but rather a bug or whatever you want to call it, from the extracting tools, so that's not something that you should rely on. If you want that feature for security reasons, that's something you should ask in a separate question. – dunni May 30 '22 at 16:26
  • Ok, I understand that it was bug in SpringBoot all these days until 2.6.x was released. And your point is that this bug was fixed in SpringBoot version 2.6.x. But Springboot documentation still says fully executable jar is not extractable. Why SpringBoot documentation is not updated if this bug was fixed. Please refer the SpringBoot documentation. https://docs.spring.io/spring-boot/docs/2.6.7/gradle-plugin/reference/htmlsingle/#packaging-executable.configuring.launch-script Section: Making an Archive Fully Executable – Nagesh May 31 '22 at 04:29
  • 1
    It only says, that some tools `may` fail to extract it. That's different from `always failing`. And again, it was not a bug in Spring Boot, it's a bug in those tools which are used to extract the JAR (like the `jar` tool). – dunni May 31 '22 at 05:23
  • If it is a bug those tools, executbale jar generated using Spring 2.5.13 is not extractable and executable jar generated using 2.6.7 is extractable. If those tools have fixed the issue, it should have been fixed for both cases. I dont think so your answer is justifiable. – Nagesh May 31 '22 at 06:54
  • 1
    It is certainly possible, that there were some Spring Boot changes, which those tools can handle now. But since the non-extractability was never a feature earlier, it's not something you can reproduce now, that's what i meant. – dunni May 31 '22 at 06:56