我正在将Maven-shade-plugin与Sprint Boot一起使用。我已将spring-boot依赖项定义为:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
我已经在pom.xml的<parent>
标记中定义了项目专用的uber-pom,因此无法在spring-boot-starter-parent
标记中使用<parent>
。
现在,当我执行mvn clean install
时,出现以下异常:
`[ERROR] Failed to execute goal org.apache.maven.plugins:maven-shade-plugin:3.1.1:shade (default) on project myapp: Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:3.1.1:shade for parameter transformers: Cannot load implementation hint 'org.springframework.boot.maven.PropertiesMergingResourceTransformer'`,
明确表示无法找到PropertiesMergingResourceTransformer
的实现。如果我使用<parent>
标记中定义的Spring-boot配置,则可以正常工作。
但是,如果我完全删除了maven-shade-plugin配置中的PropertiesMergingResourceTransformer
配置,则捆绑的jar无法执行,并给出以下异常:
`java.lang.IllegalArgumentException: No auto configuration classes found in META-INF/spring.factories. If you are using a custom packaging, make sure that file is correct.
at org.springframework.util.Assert.notEmpty(Assert.java:450) ~[myapp-1.0-SNAPSHOT.jar:na]
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.getCandidateConfigurations(AutoConfigurationImportSelector.java:160) ~[myapp-1.0-SNAPSHOT.jar:na]
at org.springframework.boot.autoconfigure.AutoConfigurationImportSelector.selectImports(AutoConfigurationImportSelector.java:96) ~[myapp-1.0-SNAPSHOT.jar:na]`
有人可以帮忙吗?
供参考:这是已解决的maven-shade-plugin问题:https://github.com/spring-projects/spring-boot/issues/11200
但是,似乎只有在<parent>
标签而不是<dependencyManagement>
中配置spring-boot依赖项时,它才起作用
在尝试使用spring-boot-maven-plugin时,运行jar时出现以下异常:
`Exception in thread "main" java.lang.IllegalStateException: Failed to get nested archive for entry BOOT-INF/lib/spring-boot-2.0.2.RELEASE.jar
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/spring-boot-2.0.2.RELEASE.jar'
at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:254)
at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:239)
at org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:103)
... 4 more
Caused by: java.lang.IllegalStateException: Unable to open nested entry 'BOOT-INF/lib/spring-boot-2.0.2.RELEASE.jar'. It has been compressed and nested jar files must be stored without compression. Please check the mechanism used to create your executable jar file
at org.springframework.boot.loader.jar.JarFile.createJarFileFromFileEntry(JarFile.java:282)
at org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(JarFile.java:262)
at org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:250)
... 6 more`
答案 0 :(得分:0)
希望您现在已经解决了这个问题,但是在同样的问题上花费了几个小时之后,我意识到需要包含spring-boot-maven-plugin
作为对maven-shade-plugin
的依赖:< / p>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<goals><goal>shade</goal></goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
<resource>META-INF/spring.factories</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${start-class}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>