欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Gradle构建SpringBoot(Eclipse)

程序员文章站 2022-05-03 13:09:38
...

Gradle构建SpringBoot

1.配置build.gradle

/*
 * This file was generated by the Gradle 'init' task.
 *
 * This generated file contains a sample Java Library project to get you started.
 * For more details take a look at the Java Libraries chapter in the Gradle
 * User Manual available at https://docs.gradle.org/6.0/userguide/java_library_plugin.html
 */
plugins {
    // Apply the java-library plugin to add support for Java Library
    id 'java-library'
    id 'org.springframework.boot' version '2.1.1.RELEASE'
}

repositories {
    // Use jcenter for resolving dependencies.
    // You can declare any Maven/Ivy/file repository here.
    //jcenter()
    // 优先使用国内源
    maven { url 'https://maven.aliyun.com/repository/public' }
    mavenCentral()
}

// 指定java版本
sourceCompatibility = 1.8
targetCompatibility = 1.8
// 使用spring boot
apply plugin: "org.springframework.boot"
// 使用spring boot的自动依赖管理
apply plugin: 'io.spring.dependency-management'  //应用的插件

dependencies {
    // This dependency is exported to consumers, that is to say found on their compile classpath.
    api 'org.apache.commons:commons-math3:3.6.1'

	// 让spring-boot支持gradle
    //classpath("org.springframework.boot:spring-boot-gradle-plugin:2.1.1.RELEASE")
    // This dependency is used internally, and not exposed to consumers on their own compile classpath.
    implementation 'com.google.guava:guava:28.0-jre'
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.boot:spring-boot-devtools'
	
    // Use JUnit test framework
    //testImplementation 'junit:junit:4.12'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    
}

2.配置SpringBootApplication项目启动类

package com.lius;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class App {

	public static void main(String[] args) {
		SpringApplication.run(App.class, args);
	}
}

3.配置Controller

package com.lius.controllers;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>测试Controller类</p>
 * @author lius
 *
 */
@RestController  //@aaa@qq.com
public class testController {

	//测试接口
	@RequestMapping("/test")
	public String gradleController() {
		
		return String.format("<h1><center style=\"color:red;font-style:italic;\">%s</center></h1>",
				"Welcome to use SpringBoot of Gradle!");
	}
}

4.构建成功

Gradle构建SpringBoot(Eclipse)