问题产生原因:由于服务器的相关配置资源在本地电脑无法直接访问导致最后打包失败,比如数据库的连接地址,redis的连接地址,logback.xml配置的日志路径在本地无法生成等,报错如下:
FeedautoApplicationTests > contextLoads() FAILED
java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:132
Caused by: java.lang.IllegalStateException at LoggingApplicationListener.java:328
Caused by: java.lang.IllegalStateException at LogbackLoggingSystem.java:179
1 test completed, 1 failed
解决方案:
在build.gradle中注释测试单元即可:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation(project(':baselib'))
implementation(project(':push'))
// implementation(project(':thirdlogin'))
//mysql
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.2'
runtimeOnly 'mysql:mysql-connector-java'
implementation 'com.google.guava:guava:31.1-jre'
implementation 'com.alibaba:fastjson:1.2.79'
}
// 测试单元
//tasks.named('test') {
// useJUnitPlatform()
//}