在子工程中可以使用parent获取父工程

//指定使用什么版本的JDK语法编译源代码,跟编译环境有关,在有java插件时才能用
sourceCompatibility = 1.8
//指定生成特定于某个JDK版本的class文件:跟运行环境有关,在有java插件时才能用
targetCompatibility = 1.8
//业务编码字符集,注意这是指定源码解码的字符集[编译器
JcompileJava.options.encoding "UTF一8"
//测试编码字符集,注意这是指定源码解码的字符集[编译器]
compileTestJava. options.encoding "UTF一8"
//编译JAVA文件时采用UTF-8 :注意这是指定源码编码的字符集【源文件】
tasks.withType (JavaCompile) {
options.encoding = "UTF一8"
)
//编译JAVA文件时采用UTF-8 :注意这是指定文档编码的字符集【源文件】
tasks.withType (Javadoc) {
options.encoding ="UTF一8"
)
配置在父工程中,对子工程无效
我们可以在其中配置多个仓库进行使用
repositories i
//gradle中会按着仓库配置的顺序,从上往下依次去对应的仓库中找所需要的jar包:
//如果找到,则停止向下搜索,如果找不到,继续在下面的仓库中查找
//指定去本地某个磁盘目录中查找:使用本地file文件协议:一般不用这种方式
maven { url 'file: ///D:/gradle/gradleRepos' }
maven { url "$rootDir/lib/release" }
//指定去maven的本地仓库查找
mavenLocal ()
//指定去maven的私服或者第三方镜像仓库查找
maven { name "Alibaba" ; url "https : //maven.aliyun . com/repository/public" }maven { name "Bstek" ; url "https: / /nexus ,bsdn.org/content/groups/public/" }
//指定去maven的远程仓库查找:即https : //repo.maven.apache.org/maven2/
mavenCentral ()
//去google仓库查找
google ()
我们可以使用这两个属性进行任务配置等操作
allprojects {
tasks.create ( ' hello ' ) {
println "project name is $task.project.name"
}
}
如下
project('kid1'){
//书写build.gradle的各种属性
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.0'
implementation files('lib/mybatis-plus-spring-starter.jar','lib/mysql-connect-java.jar')
implementation fileTree('dir':'lib',includes: ['*.jar'])
}
}
Project和Task都允许用户添加额外的自定义属性,要添加额外的属性,通过应用所属对象的ext 属性即可实现。添加之后可以通过ext属性对自定义属性读取和设置,如果要同时添加多个自定义属性,可以通过ext代码块
ext{
maker="xxx"
projectVersion="1.0"
sdk=[
minVersion:JavaVersion.VERSION_1_8
]
}
我们使用的时候直接使用$取值即可
将写好的模块发布,提供他人使用

plugins {
id 'maven-publish'
}
publishing{
publications{
myLibrary(MavenPublication){
groupId = 'cn.fly.xxx'
artifactId = 'xxx'
version = '1.0.1'
from components.java //设置发布jar包
}
}
repositories {
//本地仓库
mavenLocal()
//发布到私服
maven{
name = '私服仓库名称'
url = '本地仓库地址或私服仓库地址'
def releasesRepoUrl = layout.buildDirectory.dir('repos/releases')
def snapshotsRepoUrl = layout.buildDirectory.dir('repos/snapshots')
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
//配置认证信息
// credentials{
// username='zhangsan'
// password='xxxxxxxx'
// }
}
}
}
generatePomFileForPubNamePublication:生成pom文件publishPubNamePublication.ToRepoNameRepository:发布项目到指定仓库.如果没有仓库名,默认为mavenpublishPubNamePublicationToMavenLocal:将PubName 发布复制到本地Maven仓库中包括POM文件和其他元数据。publish:发布到repositories中指定的仓库(为比如Maven私服)publishToMavenLocal: 执行所有发布任务中的操作发布到本地 maven仓库【默认在用户目录下的.m2/repository】。
我们需要添加java-library的插件
plugins {
id 'java-library'
}
并配置如下属性
javadoc.options.encoding="UTF-8"
java{
withJavadocJar()
withSourcesJar()
}