我的SpringBoot项目依赖于一个大型Maven项目:
aSpringBootProject / build.gradle:
...
dependencies {
...
implementation 'my.big:maven.dependency'
...
}
这个大的Maven项目依赖于仅包含依赖项的subModule:
bigMavenDependency / pom.xml
...
<dependencies>
...
<dependency>
<group>my.big</group>
<artefact>sub.module</artefact>
</dependency>
...
</dependencies>
bigSubModule / pom.xml
...
<package>pom</package>
...
<dependencies>
<!-- a lot of dependencies here -->
</dependencies>
构建bootJar并运行它(java -jar aSpringBootProject.jar
)时,出现此错误:
Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/sub-module-1.0-SNAPSHOT.pom
at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:108)
...
Caused by: java.io.IOException: Unable to open nested jar file 'BOOT-INF/lib/sub-module-1.0-SNAPSHOT.pom'
at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:254)
...
Caused by: java.io.IOException: Unable to find ZIP central directory records after reading 2628 bytes
at org.springframework.boot.loader.jar.CentralDirectoryEndRecord.<init>(CentralDirectoryEndRecord.java:65)
解压缩bootJar会给我一个pom文件,其中应该包含很多jar文件。
gradle bootRun
命令就像一个超级按钮。
一种解决方法是排除子模块,然后将其作为依赖项添加到我的build.gradle中:
...
dependencies {
...
implementation 'my.big:maven.dependency' {
exclude 'my.big:sub.module'
}
implementation 'my.big:sub.module'
...
}
我在哪里错了?
答案 0 :(得分:1)
您可以尝试:
...
<dependencies>
...
<dependency>
<group>my.big</group>
<artefact>sub.module</artefact>
(here try <packaging>jar</packaging> or <type>jar</type>)
</dependency>
...
</dependencies>
在spring的boot-jar中使用compile group: 'com.fasterxml.jackson', name: 'jackson-bom', version: '2.9.8', ext: 'pom'
时,gradle中存在相同的问题。当我删除, ext: 'pom'
后,问题就解决了。