首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在添加SpringBoot配置作为<dependencyManagement>标签时使用maven-shade-plugin的PropertiesMergingResourceTransformer

如何在添加SpringBoot配置作为<dependencyManagement>标签时使用maven-shade-plugin的PropertiesMergingResourceTransformer
EN

Stack Overflow用户
提问于 2018-07-25 22:53:29
回答 1查看 2.7K关注 0票数 1

我正在使用maven-shade-plugin和Sprint Boot。我已经定义了spring-boot依赖项如下:

代码语言:javascript
复制
<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,所以不能在<parent>标签中使用spring-boot-starter-parent

现在,当我执行mvn clean install时,我会得到以下异常:

代码语言:javascript
复制
`[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将无法执行,并给出如下异常:

代码语言:javascript
复制
`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时得到下面的异常:

代码语言:javascript
复制
`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`
EN

回答 1

Stack Overflow用户

发布于 2019-05-23 21:55:15

希望您现在已经解决了这个问题,但是在为同样的问题绞尽脑汁了几个小时之后,我意识到需要将spring-boot-maven-plugin包含为maven-shade-plugin的依赖项:

代码语言:javascript
复制
<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>
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51521953

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档