最近有个需求要在本地进行测试,需要打包,但是 Gradle 又不熟悉,打包的时候报错,故整理之,以供后人瞻仰。。。
-
报错信息:
10:36:48 AM: Executing task 'bootRepackage'... FAILURE: Build failed with an exception. * Where: Build file '/Users/yyyy/Documents/Git/GitLab/xxx/build.gradle' line: 23 * What went wrong: A problem occurred evaluating root project 'datacenter'. > Failed to apply plugin [class 'io.spring.gradle.dependencymanagement.DependencyManagementPlugin'] > Could not create task of type 'DependencyManagementReportTask'. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. BUILD FAILED Total time: 0.469 secs No service o f type StyledTextOutputFactory available in ProjectScopeServices. Open File 10:36:49 AM: Task execution finished 'bootRepackage'.
- 问题解决:在build.gradle中的
buildscript
→dependencies
中添加如下依赖(版本自己斟酌一下):classpath 'io.spring.gradle:dependency-management-plugin:0.6.1.RELEASE'
- 问题解决:在build.gradle中的
-
单独使用 jar 打包,运行报错:
java -jar project.jar Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication at com.ainemo.Application.main(Application.java:13) Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication at java.net.URLClassLoader.findClass(URLClassLoader.java:382) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 1 more
- 问题解决:先使用 jar 打包,再运行 bootRepackage,找到:
build/libs/project.jar
即可,为何这样做能成功?原因尚不明确,这是急匆匆的解决方案 - Gradle build 运行即可,如果项目改为了 war,你需要临时干掉 war 的支持,如插件
apply plugin: 'war'
和war{manifest....
- 问题解决:先使用 jar 打包,再运行 bootRepackage,找到: