gradle总结
- 安装
点击查看详情
# 下载到本地直接解压
# 配置环境变量
GRADLE_HOME = C:\Program Files\gradle-7.6
GRADLE_USER_HOME = C:\Users\ychen\.gradle
PATH = %GRADLE_HOME%\bin
# 打开cmd:gradle -v
- 修改maven下载源
# 在init.d 文件夹创建init.gradle 文件
allprojects {
repositories {
mavenLocal()
maven { name "Alibaba" ; url "https://maven.aliyun.com/repository/public" }
maven { name "Bstek" ; url "https://nexus.bsdn.org/content/groups/public/" }
mavenCentral()
}
buildscript {
repositories {
maven { name "Alibaba" ; url 'https://maven.aliyun.com/repository/public' }
maven { name "Bstek" ; url 'https://nexus.bsdn.org/content/groups/public/' }
maven { name "M2" ; url 'https://plugins.gradle.org/m2/' }
}
}
}
# 需要配置M2_HOME
- idea配置
点击查看详情
- 过滤编译文件:添加类型,enter,apply
.gradle
.gitattributes
gradlew
gradlew.bat
- 构建spring boot项目
点击查看详情
# 方式一,build.gradle中配置
plugins {
id 'org.springframework.boot' version '2.3.7.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'java'
}
# 方式2,build.gradle中配置
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/repository/public' }
}
dependencies {
classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.4.1' // 只需在这里指定1个版本号即可
}
}
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
- 项目配置
点击查看详情
# build.gradle
dependencies {
// 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'
// 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'
// lombok
implementation 'org.projectlombok:lombok:1.18.8'
annotationProcessor 'org.projectlombok:lombok:1.18.8'
// 使用junit5
testImplementation("org.junit.jupiter:junit-jupiter-api:5.1.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.1.0")
}
test {
useJUnitPlatform()
}
# yml
server:
port: 8080
error:
whitelabel:
enabled: true
spring:
application:
name: app
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'
- 打包
点击查看详情
- 使用java -jar启动报错
jar中没有主清单属性
时 - 使用如下方式打包
点击查看详情
plugins {
id 'java'
id 'maven-publish' // 用于发布
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'com.ychen.demo'
artifactId = 'demo'
version = '1.1-SNAPSHOT'
from components.java
}
}
repositories {
maven {
allowInsecureProtocol = true
url "http://xxx.xxx.xxx.xxx:8081/repository/maven-snapshots/"
credentials {
username 'admin'
password 'admin'
}
}
}
}
-
从私服中下载:在init.gradle或项目中build.gradle中配置私服地址
-
构建cloud -> 链接