Gradle java使用
Posted 蓝天上的云℡
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Gradle java使用相关的知识,希望对你有一定的参考价值。
安装
去gradle官网或国内镜像站下载
这里我选择国内 腾讯镜像站 https://mirrors.cloud.tencent.com/gradle/ 下载 gradle-6.5.1-all.zip
然后解压,把bin路径添加到PATH变量即可
查看版本号
gradle -v
生成gradle项目
在新建/已有项目目录下初始化项目
gradle init
配置仓库源
编辑 当前项目目录/gradle/build.grade
在 repositories 里
jcenter()的上面添加镜像源地址如
maven {url "https://maven.aliyun.com/nexus/content/groups/public/" }
Java项目里使用Gradle导入JSoup第三方库的例子
1 /* 2 * This file was generated by the Gradle \'init\' task. 3 * 4 * This generated file contains a sample Java Library project to get you started. 5 * For more details take a look at the Java Libraries chapter in the Gradle 6 * User Manual available at https://docs.gradle.org/6.0.1/userguide/java_library_plugin.html 7 */ 8 9 plugins { 10 // Apply the java-library plugin to add support for Java Library 11 id \'java-library\' 12 } 13 14 repositories { 15 // Use jcenter for resolving dependencies. 16 // You can declare any Maven/Ivy/file repository here. 17 maven {url "https://maven.aliyun.com/nexus/content/groups/public/" } 18 19 jcenter() 20 } 21 22 dependencies { 23 // This dependency is exported to consumers, that is to say found on their compile classpath. 24 api \'org.apache.commons:commons-math3:3.6.1\' 25 // jsoup HTML parser library @ https://jsoup.org/ 26 compile \'org.jsoup:jsoup:1.12.1\' 27 // This dependency is used internally, and not exposed to consumers on their own compile classpath. 28 implementation \'com.google.guava:guava:28.0-jre\' 29 30 // Use JUnit test framework 31 testImplementation \'junit:junit:4.12\' 32 }
不得不说,Gradle比Maven先进多了
以上是关于Gradle java使用的主要内容,如果未能解决你的问题,请参考以下文章
如何使用模块化代码片段中的LeakCanary检测内存泄漏?
在Gradle中使用阿里巴巴Java开发规约插件进行代码检查