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

相關文章
相關標籤/搜索