Gradle java使用
安装
去gradle官网下载然后解压,把bin路径添加到PATH变量即可
查看版本号
gradle -v
生成gradle项目
在新建/已有项目目录下初始化项目
gradle init
配置仓库源
编辑 当前项目目录/gradle/build.grade
在 repositories 里
jcenter()的上面添加镜像源地址如
maven {url "https://maven.aliyun.com/nexus/content/groups/public/" }
<br /><br /><img src="http://image.mamicode.com/info/201912/20191218000643774972.png" title="Gradle java使用" alt="Gradle java使用">
Java项目里使用Gradle导入JSoup第三方库的例子
/* * This file was generated by the Gradle ‘init‘ task. * * This generated file contains a sample Java Library project to get you started. * For more details take a look at the Java Libraries chapter in the Gradle * User Manual available at https://docs.gradle.org/6.0.1/userguide/java_library_plugin.html */ plugins { // Apply the java-library plugin to add support for Java Library id ‘java-library‘ } repositories { // Use jcenter for resolving dependencies. // You can declare any Maven/Ivy/file repository here. maven {url "https://maven.aliyun.com/nexus/content/groups/public/" } jcenter() } dependencies { // This dependency is exported to consumers, that is to say found on their compile classpath. api ‘org.apache.commons:commons-math3:3.6.1‘ // jsoup HTML parser library @ https://jsoup.org/ compile ‘org.jsoup:jsoup:1.12.1‘ // This dependency is used internally, and not exposed to consumers on their own compile classpath. implementation ‘com.google.guava:guava:28.0-jre‘ // Use JUnit test framework testImplementation ‘junit:junit:4.12‘ }
不得不说,Gradle比Maven先进多了