如果想不使用spring-boot-starter-parent,可以这样配置:
(1)配置使用spring-boot-dependencies
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.0.4.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
注意:一定要知名是pom import,否则会有问题。
(2)配置spring-boot-maven-plugin
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
注意:
(1) 如果不使用:maven-compiler-plugin,那么
a)从App.main运行不会有问题
b)mvn pacakge或者mvn spring-boot:run会出现问题:
INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.951 s
[INFO] Finished at: 2020-08-15T10:19:47+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project com.demo: Compilation failure: Compilation failure:
[ERROR] 不再支持源选项 5。请使用 7 或更高版本。
[ERROR] 不再支持目标选项 5。请使用 7 或更高版本。
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
(2) spring-boot-maven-plugin一定要配置goal为repackage,否则mvn package无法正常工作。mvn package可以正常打包,但是java -jar xxx 运行jar包会出现错误:
➜ comdemo1 java -jar /Users/apple/work/code/springboot/comdemo1/target/com.demo-1.0-SNAPSHOT.jar
/Users/apple/work/code/springboot/comdemo1/target/com.demo-1.0-SNAPSHOT.jar中没有主清单属性
网友评论