Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle POM-only dependencies cause jar application loader to fail #16001

Closed
DanielThomas opened this issue Feb 20, 2019 · 5 comments
Closed

Gradle POM-only dependencies cause jar application loader to fail #16001

DanielThomas opened this issue Feb 20, 2019 · 5 comments
Labels
type: bug A general bug
Milestone

Comments

@DanielThomas
Copy link
Contributor

Dependencies with pom packaging are included on the classpath and the boot jar process nor the loader considers the type of the file cause application startup to fail.

To reproduce take the following build:

plugins {
	id 'org.springframework.boot' version '2.1.3.RELEASE'
	id 'java'
}

repositories {
	mavenCentral()
}

dependencies {
	compile 'com.googlecode.matrix-toolkits-java:mtj:1.0.3'
}

bootJar {
	mainClassName = 'com.example.ExampleApplication'
}

Run bootJar and run java -jar build/libs/spring.jar and note the failure:

Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/all-1.1.2.pom
	at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:108)
	at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(JarFileArchive.java:86)
	at org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(ExecutableArchiveLauncher.java:70)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:49)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: java.io.IOException: Unable to open nested jar file 'BOOT-INF/lib/all-1.1.2.pom'
	at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:256)
	at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:241)
	at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:103)
	... 4 more
Caused by: java.io.IOException: Unable to find ZIP central directory records after reading 4270 bytes
	at org.springframework.boot.loader.jar.CentralDirectoryEndRecord.<init>(CentralDirectoryEndRecord.java:65)
	at org.springframework.boot.loader.jar.CentralDirectoryParser.parse(CentralDirectoryParser.java:52)
	at org.springframework.boot.loader.jar.JarFile.<init>(JarFile.java:123)
	at org.springframework.boot.loader.jar.JarFile.<init>(JarFile.java:111)
	at org.springframework.boot.loader.jar.JarFile.createJarFileFromFileEntry(JarFile.java:289)
	at org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(JarFile.java:264)
	at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:252)
	... 6 more

POM files can be expected on configurations for either pom packaged dependencies like this, or for pom dependency management files for new native BOM support.

Gradle version:

------------------------------------------------------------
Gradle 5.1.1
------------------------------------------------------------

Build time:   2019-01-10 23:05:02 UTC
Revision:     3c9abb645fb83932c44e8610642393ad62116807

Kotlin DSL:   1.1.1
Kotlin:       1.3.11
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_202 (Azul Systems, Inc. 25.202-b05)
OS:           Mac OS X 10.14.3 x86_64
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 20, 2019
@snicoll
Copy link
Member

snicoll commented Feb 20, 2019

For the record, the Maven plugin seems to skip pom artifacts.

@wilkinsona
Copy link
Member

We just package whatever is on the classpath, with directories going into BOOT-INF/classes and files into BOOT-INF/lib. It doesn't make much sense to me that Gradle apparently adds poms to the classpath, but if that's what it does I guess we'll have to filter them out.

@wilkinsona wilkinsona added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 20, 2019
@wilkinsona wilkinsona added this to the 2.1.x milestone Feb 20, 2019
@wilkinsona wilkinsona modified the milestones: 2.1.x, 2.1.4 Feb 20, 2019
@ljacomet
Copy link

Just as an FYI, from the linked Gradle issue, I did some investigation and found that pom files for dependencies with <type>pom</type are added to the Maven build classpath. Which matches the comment from Stéphane.
See this comment for details.

So Gradle is consistent with Maven there.

@wilkinsona
Copy link
Member

I stand corrected. Thanks, @ljacomet. I'm also surprised that Maven behaves the way that it does, but there are probably good reasons for it of which I am ignorant. Our Maven support for building fat jars is already written in such a way that it'll ignore a pom. Our Gradle support has been updated in 59430a2 to behave the same way.

@ljacomet
Copy link

Same surprise, assumptions on the reasons and ignorance here 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

5 participants