学习写代码呀

导航

gradle配置

1、gradle项目gradle-wrapper.properties

gradle-wrapper.properties存放的是项目自身推荐的gradle版本比如
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

详情:
https://segmentfault.com/a/1190000019622387?utm_source=tag-newest
https://my.oschina.net/formatkm/blog/1822900

gradle 、gradle wrapper 、 gradle plugin:
https://www.cnblogs.com/zadomn0920/p/6186526.html

自定义打jar:
https://blog.csdn.net/qq_15364915/article/details/52167052

自动化Gradle项目打包并Docker部署:

https://www.jianshu.com/p/e4b7b7cfab09

 2、spring-boot-gradle-plugin插件

Spring Boot Gradle Plugin为Spring Boot提供了对Gradle的支持,允许你将打包可执行的jar或者war archives,运行Spring Boot程序,然后使用spring-boot-dependencies提供的依赖管理。



build.gradle例子一:

//buildscript {
// repositories {
// jcenter()
// }
// dependencies {
//gradle运行自身需要的gradle插件版本,gradle插件和gradle是两个独立的东西,是android studio使用gradle构建时使用
// classpath 'com.android.tools.build: gradle:2.1.0'
// // NOTE: Do not place your application dependencies here; they belong
// // in the individual module build.gradle files
// }
//}


plugins {
id 'java'
id 'org.springframework.boot' version '2.0.1.RELEASE'
}
apply plugin: 'java'
//第二种引入方式:应用依赖管理插件,自动给插件追加版本号(建议使用此配置)
apply plugin: 'io.spring.dependency-management'

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
mavenLocal() //优先查找本地库,gradle默认会按以下顺序去查找本地的仓库:USER_HOME/.m2/settings.xml >> M2_HOME/conf/settings.xml >> USER_HOME/.m2/repository
maven { url ("http://maven.aliyun.com/nexus/content/groups/public/")}
mavenCentral()
}
ext {
springbootVersion = '2.1.14.RELEASE'
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
}
build.gradle例子二:
buildscript {
ext{
springBootVersion = '2.0.1.RELEASE'
}
repositories {
mavenLocal()
maven { url 'https://maven.aliyun.com/repository/public' }
mavenCentral()
}
dependencies {
// spring-boot支持gradle
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

//需要用到的插件DSL
plugins {
id 'java'
//统一定义springboot版本
// id 'org.springframework.boot' version '2.0.1.RELEASE'
}
apply plugin: 'java'
//依赖管理,统一依赖版本
apply plugin: 'io.spring.dependency-management'
apply plugin: 'org.springframework.boot'
//Gradle自动生成Intellij的项目文件
//Intellij项目文件主要有三种类型。.ipr Intellij工程文件;.iml Intellij 模块文件;.iws Intellij 工作区文件
apply plugin: 'idea'
//可能是新版springboot DSL,或者错误的id命名
//apply plugin: 'spring-boot'

group 'org.example'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenLocal()
maven { url "http://nexusproxy.paas.x/repository/maven-public/"}
maven { url "http://nexushost.paas.x/repository/maven-public/"}
maven { url 'https://maven.aliyun.com/repository/public' }
mavenCentral()
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-devtools")
//引入依赖,只用于当前模块
// implementation("org.springframe.boot:spring-boot-starter-jpa:2.0.6.RELEASE")
}
task printSomething(){
println("springboot版本:${springBootVersion}")
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
}
//打可执行jar
bootJar {
mainClassName = 'com.study.RunApplication'
}
//依赖插件:apply plugin: 'org.springframework.boot'
//springBoot{
// mainClassName = 'com.study.RunApplication'
//}

//强制定义所有相关依赖版本
//ext{
// springCloudDependenciesVersion = 'Greenwich.SR5'
//}
//设置commons-pool2版本为'2.6.1'Spring依赖的是2.6.2
//ext['commons-pool2.version'] = '2.6.1'
 




 

posted on 2020-06-29 20:53  学习写代码呀  阅读(544)  评论(0编辑  收藏  举报