文章目录
- Idea中配置
- Gradle项目
- project目录
- settings.gradle
- build.gradle
- gradlew
- gradlew.bat
- Gradle Build生命周期
- 编写Settings.gradle
- 编写Build.gradle
- Tasks
- Plugins
Idea中配置
配置项:gradle位置 及仓库位置
Gradle项目
Task,settings.gradle,build.gradle,wrapper 核心概念
project目录
settings.gradle
如配置root project 及 sub project
rootProject.name = 'poi'include 'poi', 'poi-ooxml-full', 'poi-ooxml-lite-agent', 'poi-scratchpad','poi-ooxml', 'poi-excelant', 'poi-examples', 'poi-integration' , 'poi-ooxml-lite'
build.gradle
配置依赖,插件,镜像源的地方
plugins {id 'java'
}group = 'org.example'
version = '1.0-SNAPSHOT'repositories {maven { url 'https://maven.tuna.tsinghua.edu.cn/nexus/content/groups/public' }maven { url 'https://maven.aliyun.com/repository/central' }maven { url 'https://maven.jуйyiyun.com/repository/central' }// 其他国内镜像源}dependencies {testImplementation platform('org.junit:junit-bom:5.10.0')testImplementation 'org.junit.jupiter:junit-jupiter'
}test {useJUnitPlatform()
}
gradlew
Linux或者Mac系统下Wrapper执行脚本
gradlew.bat
Windows系统下Wrapper执行脚本
Gradle Build生命周期
编写Settings.gradle
等价于Settings()对象,settings.gradle可以调用本身的属性和方法进行配置
具体Property和Method查官网API
rootProject.name = 'poi'include 'poi', 'poi-ooxml-full', 'poi-ooxml-lite-agent', 'poi-scratchpad','poi-ooxml', 'poi-excelant', 'poi-examples', 'poi-integration' , 'poi-ooxml-lite'
编写Build.gradle
等价于Project()对象,可以调用属性和方法进行配置、
依赖引入直接去Maven仓库里找对应包cv即可
/*插件*/
plugins {id 'java'
}
/*远程仓库地址*/
repositories {maven { url 'https://maven.tuna.tsinghua.edu.cn/nexus/content/groups/public' }maven { url 'https://maven.aliyun.com/repository/central' }maven { url 'https://maven.jуйyiyun.com/repository/central' }// 其他国内镜像源}/*依赖*/
dependencies {implementation("com.google.guava:guava:32.1.1-jre")testImplementation platform('org.junit:junit-bom:5.10.0')testImplementation 'org.junit.jupiter:junit-jupiter'// https://mvnrepository.com/artifact/org.apache.poi/poiimplementation group: 'org.apache.poi', name: 'poi', version: '5.2.3'
// https://mvnrepository.com/artifact/org.apache.pdfbox/pdfboximplementation group: 'org.apache.pdfbox', name: 'pdfbox', version: '3.0.1'
}
Tasks
-
Lifecycle tasks
生命周期内的task
-
Actionable tasks
单独一个任务
/*有依赖的task*/
tasks.register('hello') {doLast {println 'Hello world!'}
}
tasks.register('intro') {dependsOn tasks.hellodoLast {println "I'm Gradle"}
}/*指定group*/
tasks.register("hello") {group = "Custom"description = "A lovely greeting task."doLast {println("Hello world!")}
}
Plugins
分为Core plugins ,Community plugins ,和local plugins
/*core plugin id一个参数即可*/
plugins {id("java")
}
/*community plugin 一般id和version两个参数*/
plugins {id «plugin id» version «plugin version»
}
插件必须在settings.gradle指定,且在最前行
pluginManagement {plugins {}resolutionStrategy {}repositories {}
}
rootProject.name = 'plugin-management'