由於項目需要繼承自己平臺的父 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>
添加後再次打包, 一切正常。