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

因为项目须要继承本身平台的父 parent , 有的模块是纯 api ,不能有任何依赖, 因此父 parent 不能直接引入 springboot, 单独给非 boot 项目排除依赖的话又特别的麻烦, 且很差把控。html

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

官方让添加以下依赖管理api

<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 的方式启动项目。springboot

通过搜索, 找到了以下解决方案
原连接maven

<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>

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

相关文章
相关标签/搜索