gradle 构建springboot 项目两种方式

第一种直接用插件 spring-boot-gradle-plugin

  • 无需写入 版本
buildscript {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/public' }
    }
    dependencies {
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.7.3'
    }
}

plugins {
    id("java")
}

apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

第二种使用 需要指定 dependency-management 版本

  • org.springframework.boot 和 io.spring.dependency-management 指定版本
plugins {
    id("java")
    id  'org.springframework.boot' version '2.7.3'
    id  'io.spring.dependency-management' version '1.0.7.RELEASE'
}

我推荐第一种

buildscript {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/public' }
    }
    dependencies {
        classpath 'org.springframework.boot:spring-boot-gradle-plugin:2.7.3'
    }
}

plugins {
    id("java")
}

apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'


group = 'com.example'
sourceCompatibility = '1.8'

repositories {
    maven { url 'https://maven.aliyun.com/repository/jcenter' }
    maven { url 'https://maven.aliyun.com/repository/google' }
    maven { url 'https://maven.aliyun.com/repository/central' }
    maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
    maven { url 'https://maven.aliyun.com/repository/apache-snapshots' }
    mavenCentral()
    flatDir {
        dirs 'lib'
    }
}


dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.junit.jupiter:junit-jupiter:5.8.1'
    testImplementation 'org.junit.jupiter:junit-engine:5.8.1'

}

tasks.named('test') {
    useJUnitPlatform()
}

测试用例在 2.4.5之后重大改进

package com.example.test_pro_gradle;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledIfSystemProperty;
import org.springframework.boot.test.context.SpringBootTest;


@SpringBootTest
class TestProGradleApplicationTest {
    @Test
    void contextLoads() {
        // 测试逻辑...
    }

    @Test
    @DisabledIfSystemProperty(named = "os.arch", matches = ".*32.*")
    void disabledOn32BitArch() {
        // 测试逻辑...
    }

}
posted @ 2023-06-12 18:07  vx_guanchaoguo0  阅读(478)  评论(0编辑  收藏  举报