gradle 1+1
来源:互联网 发布:3cdaemon 端口 编辑:程序博客网 时间:2024/05/21 09:21
设置编译等级
sourceCompatibility=1.6targetCompatibility=1.6
依赖包
dependencies { compile "group:name:version"//运行时候的依赖包 testCompile "group:name:version"//测试依赖包 //compile org.hibernate:hibernate-core:3.6.7.Final'}
依赖本地文件
includes表示在include内的文件才会被包含其他的文件不被包含excludes于includes相反。
dependencies {compile fileTree(dir:"WebRoot/WEB-INF/lib/",includes:["c3p0-0.9.1.jar","ojdbc14.jar"])//只引入c3p0-0.9.1.jar,ojdbc14.jar 其他jar均不引入compile fileTree(dir:"WebRoot2/WEB-INF/lib/",excludes:["c3p0-0.9.1.jar","ojdbc14.jar"])//除c3p0-0.9.1.jar,ojdbc14.jar 其他jar均引入}
去除传递依赖
方法1:
dependencies { compile ("xxx:xxx:xxx"){ transitive = false//去除传递依赖}}
方法2
dependencies { compile "xxx:xxx:xxx@jar"//加入@jar去除传递依赖}
比如xxx依赖于xxx2 那么如果不配置transitive=false那么xxx2.包括xxx2所依赖的包都会被下载。
例如:
ext{ springversion="3.2.4.RELEASE"}dependencies { compile "org.springframework:spring-aop:${springversion}"}
查看依赖使用命令 gradle dependencies
效果如下
红色部分就是传递依赖的东西。这些东西都会被下载即使我们不用
当加去除传递依赖后
ext{ springversion="3.2.4.RELEASE"}dependencies { compile ("org.springframework:spring-aop:${springversion}"){ transitive = false//去除传递依赖}}
效果。不会再下载依赖的包了。只会下载我们配置的包
全局去除传递依赖
configurations { all*.transitive = false}
去除部分依赖
我们想引入传递依赖的大部分jar,但是有的部分我们不想引入
dependencies {compile("xxx:xxx:xx"){exclude group: 'xxx', module: 'xxx'}}
全局去除部分依赖
configurations { all*.exclude group: 'xxx'}将不会有group 'xxx'的依赖包
更改webRoot名称
war{webAppDirName="newName"}
设置sourceSets
sourceSets { main { java { srcDirs '源码目录1','源码目录' //都是相对路径 } resources { srcDirs '资源目录1','资源目录2' //都是相对路径 } } test { java { srcDirs '测试源码目录1' ,'测试源码目录2'//都是相对路径 } resources { srcDirs '测试资源目录1','测试资源目录2' //都是相对路径 } }}
设置版本号
version="1.0"
设置变量
基于代码
ext{ 变量名称=值}
配置代码仓库
maven仓库
repositories { maven {url "http://192.168.1.10:8081/nexus/content/groups/public"} maven {url "http://192.168.1.10:8081/nexus/content/repositories/local"} maven{ url 'http://maven.oschina.net/content/groups/public/'} mavenCentral()}
拷贝依赖到指定目录
task copyjars(type: Copy){ from configurations.compile into "c:/WebRoot/WEB-INF/lib2"}
发布包到maven仓库
apply plugin: 'maven'apply plugin:'maven-publish'apply plugin: 'java'version="1.0"group="xx.xx.xx"task sourceJar(type: Jar) {//将源码导入 from sourceSets.main.java from sourceSets.main.resources classifier "sources"}publishing { repositories { maven { url 'http://192.168.1.10:8081/nexus/content/repositories/local' credentials { username 'admin' password 'admin123' } } } publications { maven(MavenPublication) { artifacts = [jar,sourceJar] } }}
更换编译器
因为有的时候我们使用eclipse开发的代码使用jdk自带的编译器是无法通过的。这时候就需要更换编译器为我们开发环境的编译器。
compileJava { options.encoding = 'utf-8'options.debug=falseoptions.warnings=falseoptions.fork = trueoptions.forkOptions.executable = 'java'//ecj是eclipse的编译器更多参数参见eclipse ecjoptions.forkOptions.jvmArgs = ['-cp','d:\\ecj-4.4.1.jar','org.eclipse.jdt.internal.compiler.batch.Main','-target','1.5','-source','1.5']}
设置编码
[compileJava, javadoc, compileTestJava]*.options*.encoding = 'UTF-8'
javadoc乱码
javadoc{ options.addStringOption("encoding", "UTF-8") options.addStringOption("charset", "UTF-8")}
示例大全
https://github.com/pkaq/GradleSide
0 0
- Gradle-使用Gradle构建和测试-1-Hello,Gradle
- Gradle调用终端命令(gradle-2.2.1)
- Gradle 1:为什么要用Gradle
- gradle 学习系列教程1-gradle安装
- Gradle Gradle入门系列(1):简介
- gradle 知识(1) -- gradle构建工具
- gradle 1+1
- gradle学习(1)-helloworld
- Gradle探索(1)-简介
- gradle安装-1
- Gradle Tips#1-tasks
- Gradle User Guide(1)
- Gradle学习(1)
- Gradle多渠道打包 (1)
- Gradle详解1
- Gradle Tips#1-tasks
- Gradle读书笔记1
- 1 gradle 介绍 安装
- Codeforces 86C Genetic engineering
- 关于文件转换代码和openoffice服务在不同的linux上报错conversion failed: could not load input document的问题
- 《挑战程序设计竞赛》4.2.1 游戏必胜策略-推理与动态规划算法 POJ2484 2348 1082 2068 3688 1740(1)
- 操作系统的基本特性
- 架构师行为准则
- gradle 1+1
- SVN的MKACTIVITY 403 Forbidden 异常处理
- YTU 2918: Shape系列-4
- 我的博客
- document.ready和window.onload的区别
- ZEOSDBO+SQLite+Delphi7不常见异常信息的解决
- 对比windows和linux的对父进程的文件描述符继承的设置
- 2003 - Cann't connect to MySql server on - 'localhost'(10061)
- Android Studio——如何将AndroidStudio的项目提交到Github上