解决 SpringBoot 不继承父starter-parent打包不包含依赖的问题

由于项目需要继承自己平台的父 parent , 有的模块是纯 api ,不能有任何依赖, 所以父 parent 不能直接引入 springboot, 单独给非 boot 项目排除依赖的话又特别的麻烦, 且不好把控。

记得刚接触 SpringBoot 时看的官方文档里面有给方案。打开官网找了找。 
官方文档:using-boot-maven-without-a-parent

官方让添加如下依赖管理

<dependencyManagement>
    <dependencies>
        <dependency>
            <!-- Import dependency management from Spring Boot -->
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>1.5.6.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

更换父 parent 加入依赖管理后, 可以正常运行, 但是打出的包是不包含依赖的。 
也就是说, 我们不能直接使用 jar -jar demo.jar 的方式启动项目。

经过搜索, 找到了如下解决方案
原链接

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <mainClass>com.junbaor.test.App</mainClass>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>repackage</goal>
            </goals>
        </execution>
    </executions>
</plugin>

添加后再次打包, 一切正常。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章