1 生成Maven构建图
- 在根项目中 .mvn/extensions.xml 文件声明Gradle扩展
<extensions>
<extension>
<groupId>com.gradle</groupId>
<artifactId>gradle-enterprise-maven-extension</artifactId>
<version>1.0.6</version>
</extension>
</extensions>
- 运行脚本
mvn install -Dmaven.test.skip=true
同意协议,获取构建图地址,类似 https://gradle.com/s/4jhcbxcnjoog4
2 运行自动转换
gradle init
- 删除无用的 pom 文件
- 删除 .idea 文件后再重新导入项目
3 生成Gradle构建图
gradlew build --scan -x test
与之前maven的构建图对比,查漏补缺
4 验证依赖,修复问题
lambok
compileOnly 'org.projectlombok:lombok:1.18.4'
annotationProcessor 'org.projectlombok:lombok:1.18.4'
mapstruct
plugins {
...
id 'net.ltgt.apt' version '0.21'
id "net.ltgt.apt-idea" version "0.21"
}
dependencies {
...
compile "org.mapstruct:mapstruct:${mapstructVersion}"
// OR use this with Java 8 and beyond
compile "org.mapstruct:mapstruct-jdk8:${mapstructVersion}"
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
}
//设置
tasks.withType(JavaCompile) {
options.compilerArgs = [
'-Amapstruct.suppressGeneratorTimestamp=true',
'-Amapstruct.suppressGeneratorVersionInfoComment=true',
'-Amapstruct.defaultComponentModel=spring'
]
}
springboot插件指定Main函数
plugins {
id 'org.springframework.boot' version"2.1.2.RELEASE"
}
subprojects {
apply plugin: 'org.springframework.boot'
}
//指定main
bootJar {
mainClassName = 'com.wujun234.article.admin.AdminAppliction'
}
//构建
gradlew bootJar
buildscript
buildscript {
ext {
springBootVersion = '2.1.2.RELEASE'
}
repositories {
mavenLocal()
maven { url = "http://maven.aliyun.com/nexus/content/groups/public" }
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
5 速度对比
依赖都下载到本地,跳过测试,构建
- Maven首次构建41s:https://scans.gradle.com/s/xojxxkbqk2mxg
- Maven再次构建17s:https://scans.gradle.com/s/7bb2hb6tugh7s
- Gradle首次构建25s:https://scans.gradle.com/s/llw57w36ulr6g/
- Gradle再次构建4s:https://scans.gradle.com/s/q6rghvuvipzyw
删除本地仓库后
- Maven 首次构建1m 49s: https://scans.gradle.com/s/yetvwtuqx76f2
- Gradle首次构建1m 21s: https://scans.gradle.com/s/svoefjh7n6g2s