Gradle 第五讲 之 java插件的使用
来源:互联网 发布:济南万达mac 编辑:程序博客网 时间:2024/06/16 09:27
在完成前面几讲之后,后面的貌似就没有那么轻松了,本讲讲结合java插件来介绍gradle在java中的使用
1.添加java插件
2.添加依赖仓库
3.添加编译引用
4.添加自定义jar包的引用
5.定制MANIFEST.MF文件
6.jar包的发布
1.添加java插件
apply plugin: 'java'
就这一句话,我们就已经将java插件引入了,输入:wudideMacBook-Pro:gradle ***$ gradle -q tasks
------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------
Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
buildDependents - Assembles and tests this project and all projects that depend on it.
buildNeeded - Assembles and tests this project and all projects it depends on.
classes - Assembles classes 'main'.
jar - Assembles a jar archive containing the main classes.
testClasses - Assembles classes 'test'.
Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]
Documentation tasks
-------------------
javadoc - Generates Javadoc API documentation for the main source code.
Help tasks
----------
components - Displays the components produced by root project 'gradle'. [incubating]
dependencies - Displays all dependencies declared in root project 'gradle'.
dependencyInsight - Displays the insight into a specific dependency in root project 'gradle'.
help - Displays a help message.
model - Displays the configuration model of root project 'gradle'. [incubating]
projects - Displays the sub-projects of root project 'gradle'.
properties - Displays the properties of root project 'gradle'.
tasks - Displays the tasks runnable from root project 'gradle'.
Verification tasks
------------------
check - Runs all checks.
clean - Deletes the build directory.
test - Runs the unit tests.
Rules
-----
Pattern: clean<TaskName>: Cleans the output files of a task.
Pattern: build<ConfigurationName>: Assembles the artifacts of a configuration.
Pattern: upload<ConfigurationName>: Assembles and uploads the artifacts belonging to a configuration.
以上的所有task启示都是java插件定义好的,我们可以直接使用就可以了
2.添加依赖仓库
repositories {
mavenCentral()
}
这里是添加了Maven仓库,我们在使用的时候,就可以在这里进行下载查找了
http://repo1.maven.org/maven2/
3.添加编译引用
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
}
这个就是添加依赖文件,这个可不是本地的依赖啊,而是去我们之前添加的依赖仓库中去查找,也就是说需要在build的时候,联网的,输入:wudideMacBook-Pro:gradle ***$ gradle build
:compileJava
Download https://repo1.maven.org/maven2/commons-collections/commons-collections/3.2/commons-collections-3.2.pom
Download https://repo1.maven.org/maven2/commons-collections/commons-collections/3.2/commons-collections-3.2.jar
> Building 0% > :compileJava > 47 KB/557 KB downloaded ....
但只需要下载一次,下载过之后,以后就会用本地的了。
4.添加自定义jar包的引用
dependencies {
compile files('libs/dex.jar')
}
5.定制MANIFEST.MF文件
sourceCompatibility = 1.7
version = '3.0'
jar {
manifest{
attributes 'Implementation-Title':'Gradle Quickstart','Implementation-Version':version
}
}
sourceCompatibility 是设置我们的java编译版本,当电脑中有多个版本时,我们可以指定
manifest中就很简单了,就是设置manifest中的值
version这个是制定当时编译出来的版本,如果是3.0 则编译出来的jar包就叫:gradle-3.0.jar
再来看一下我们生成jar包的manifest文件吧
6.jar包的发布
关于jar包的发布,我们每次编译完成自动在build文件中就会生成jar包,但这里介绍另外一种
uploadArchives {
repositories{
flatDir {
dirs 'out'
}
}
}
注意,这个方法名字是固定的,但是dirs这个是制定我们的输出目录,这个名字是可以随便取的,最后编译完成生成以下文件:
wudideMacBook-Pro:out ***$ ls
gradle-3.0.jar gradle-3.0.jar.sha1ivy-3.0.xml ivy-3.0.xml.sha1
当然你还有可以将生成的jar包直接发布到远程的地点,这里就不介绍了。- Gradle 第五讲 之 java插件的使用
- 9 gradle 之java插件的使用
- Gradle 第六讲 之 android插件的入门1
- Gradle 第七讲 之 android插件的入门2 SourceSets
- 11 gradle 之groovy 插件的使用
- Gradle 第二讲 之 创建task与变量的使用
- 第五讲 datagrid的使用
- Gradle之java插件入门
- 翻译:Gradle之 Java插件
- 《Java报表之JFreeChart》第五讲
- 12 gradle 之war 和jetty 插件的使用
- gradle templates 插件的使用
- Gradle 第四讲 之 ant使用 与 methods使用
- Java讲座第五讲
- java SE 第五讲
- Java基础第五讲
- JAVA第五讲
- gradle构建项目之java插件
- Hadoop2.2.0集群搭建
- Android性能优化之使用线程池处理异步任务
- 如何使用交叉验证(cross-validatation)
- 计算机连不上网的总结
- springMVC 拦截器
- Gradle 第五讲 之 java插件的使用
- 移动H5前端性能优化指南
- 《编程之美》——数组循环移位
- spinner改变字体颜色,大小等
- 结构风险最小化
- DOM常用API
- 查询MySQL数据占用情况
- ios 学习之 NSPredicate 模糊、精确、查询
- MySql数据库设计的8种优化方法