| |
| |
| GRADLE_HOME |
| GRADLE_USER_HOME |
| PATH |
| |
| |


-
idea配置

-
打包

-
常用命令
| |
| gradlew build |
| gradlew clean |
| gradle build |
| gradle clean |
| gradle clean build |
| |
| |
| |
| |
| |
| C:\Users\ychen224\OneDrive - DXC Production\Desktop\demo01>gradle init |
| |
| Select type of project to generate: |
| 1: basic |
| 2: application |
| 3: library |
| 4: Gradle plugin |
| Enter selection (default: basic) [1..4] 2 |
| |
| Select implementation language: |
| 1: C++ |
| 2: Groovy |
| 3: Java |
| 4: Kotlin |
| 5: Scala |
| 6: Swift |
| Enter selection (default: Java) [1..6] 3 |
| |
| Split functionality across multiple subprojects?: |
| 1: no - only one application project |
| 2: yes - application and library projects |
| Enter selection (default: no - only one application project) [1..2] 2 |
| |
| Select build script DSL: |
| 1: Groovy |
| 2: Kotlin |
| Enter selection (default: Groovy) [1..2] 1 |
| |
| Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] yes |
| |
| Project name (default: demo01): demo01 |
| |
| Source package (default: demo01): io.github.chnq |
| |
| |
| > Task :init |
| Get more help with your project: https://docs.gradle.org/7.3.3/samples/sample_building_java_applications_multi_project.html |
| |
| BUILD SUCCESSFUL in 1m 32s |
| 2 actionable tasks: 2 executed |

| # 跨子项目 + 不使用新的API |
| |
| Split functionality across multiple subprojects?: |
| 1: no - only one application project |
| 2: yes - application and library projects |
| Enter selection (default: no - only one application project) [1..2] 2 |
| |
| Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] no |

| # 不跨子项目 + 使用新的API |
| |
| Split functionality across multiple subprojects?: |
| 1: no - only one application project |
| 2: yes - application and library projects |
| Enter selection (default: no - only one application project) [1..2] 1 |
| |
| Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] yes |

| # 不跨子项目 + 不使用新的API |
| |
| Split functionality across multiple subprojects?: |
| 1: no - only one application project |
| 2: yes - application and library projects |
| Enter selection (default: no - only one application project) [1..2] 1 |
| |
| Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] no |

| gradle配置 |
| jdk |
| 字符集 |
| 注解生效激活 |
| 过滤编译文件:添加类型,enter,apply |
| .gradle |
| .gitattributes |
| gradlew |
| gradlew.bat |
| |
| spring-boot-devtools |
| |
| |
| spring: |
| devtools: |
| restart: |
| enabled: true |

-
ctrl + shift + alt + /


-
spring boot模板
| |
| implementation 'org.projectlombok:lombok:1.18.8' |
| annotationProcessor 'org.projectlombok:lombok:1.18.8' |
| |
| |
| |
| |
| dependencies { |
| // |
| implementation 'com.google.guava:guava:30.1.1-jre' |
| // spring-boot-starter-web |
| implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.6.1' |
| // spring-boot-devtools |
| implementation group: 'org.springframework.boot', name: 'spring-boot-devtools', version: '2.6.1' |
| // lombok |
| compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.18.20' |
| // spring-boot-starter-test |
| testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.6.1' |
| // spring-boot-configuration-processor |
| implementation group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version: '2.6.1' |
| } |
| |
| |
| server: |
| port: 8080 |
| error: |
| whitelabel: |
| enabled: true |
| spring: |
| application: |
| name: demo01 |
| messages: |
| basename: messages |
| encoding: UTF-8 |
| devtools: |
| restart: |
| enabled: true |
| logging: |
| level: |
| com: |
| example: DEBUG |
| org: |
| springframework: |
| security: DEBUG |
| pattern: |
| console: '%clr(%d{E HH:mm:ss.SSS}){blue} %clr(%-5p) %clr(${PID}){faint} %clr(---){faint} |
| %clr([%8.15t]){cyan} %clr(%-40.40logger{0}){blue} %clr(:){red} %clr(%m){faint}%n' |
| |
| |
| @RestController |
| public class TestController { |
| @RequestMapping("/test") |
| public String test(){ |
| return "hello"; |
| } |
| } |
| |
| |
| |
| |
| http://localhost:8080/test |
| http://localhost:8080/index.html |
| |
| |
| |
| |
| Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/boot/SpringApplication |
| at io.github.ychen.App.main(App.java:13) |
| Caused by: java.lang.ClassNotFoundException: org.springframework.boot.SpringApplication |
| at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582) |
| at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) |
| at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) |
| ... 1 more |
| |
| # 参考:https://blog.csdn.net/kingboyworld/article/details/75244769 |
| |
| # build.gradle中添加 |
| apply plugin: 'war' |
| # 修改启动类 |
| @SpringBootApplication |
| public class App extends SpringBootServletInitializer { |
| public static void main(String[] args) { |
| SpringApplication.run(App.class, args); |
| } |
| @Override |
| protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { |
| return builder.sources(App.class); |
| } |
| } |
| # 控制台输入命令打包 |
| gradle build |
| # 将war包上传到服务器 |
| # 拉取tomcat镜像 |
| docker pull chniny/tomcat:9 |
| docker run -d -p 8080:8080 chniny/tomcat:9 |
| # 将war复制到tomcat容器 |
| docker cp app.war container_ID:/usr/local/tomcat/webapps |



- 编译时报错

| |
| |
| |
| |
| |
| implementation 'org.projectlombok:lombok:1.18.8' |
| annotationProcessor 'org.projectlombok:lombok:1.18.8' |
| testing { |
| suites { |
| |
| |
| |
| |
| |
| |
| test { |
| |
| useJUnit('5.13.2') |
| } |
| |
| } |
| } |
| |
| |
| testImplementation("org.junit.jupiter:junit-jupiter-api:5.1.0") |
| testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.1.0") |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 字符编码:从基础到乱码解决
· 提示词工程——AI应用必不可少的技术
2021-07-22 ubuntu入门