maven迁移到gradle

Wu Jun 2019-12-25 15:59:03
Categories: > Tags:

1 生成Maven构建图

  1. 在根项目中 .mvn/extensions.xml 文件声明Gradle扩展
<extensions>
    <extension>
        <groupId>com.gradle</groupId>
        <artifactId>gradle-enterprise-maven-extension</artifactId>
        <version>1.0.6</version>
    </extension>
</extensions>
  1. 运行脚本
mvn install -Dmaven.test.skip=true

同意协议,获取构建图地址,类似 https://gradle.com/s/4jhcbxcnjoog4

2 运行自动转换

gradle init

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 速度对比

依赖都下载到本地,跳过测试,构建

删除本地仓库后