Gradle 加载对应的jar包

1.使用eclipse创建一个java project
2.在java项目中执行gradle init (如果没有安装gradle请移步官网下载)
3.在生成build.gradle文件中编写对应的gradle脚本
4.测试代码
apply plugin: ‘java’ //告知gradle项目是一个java项目
apply plugin: ‘eclipse’ //告知gradle项目时一个eclipse项目

repositories {
jcenter() //引用依赖jar包的中央仓库
}

jar {
baseName = ‘gradle_java’ //执行gradle build 生成的压缩jar包的名字
version = ‘0.1.0’
}

sourceCompatibility = 1.8 //编译时兼用的jvm版本
targetCompatibility = 1.8

dependencies {
compile ‘joda-time:joda-time:2.2’ //依赖的jar包 注意:jar包的:左右不能含有空格,否则会报对应的jar包找不到。
testCompile ‘junit:junit:4.12’
}
5.执行gradle eclipse 将项目转为eclipse项目
6.注意:编写依赖时 compile ‘依赖的jar’,如果使用的是’依赖的jar’则不能使用变量。使用”依赖的jar”可以使用变量
eg:
dependencies {
def sprintBootVersion = “2.0.1.RELEASE”
// Spring boot
compile(“org.springframework.boot:spring-boot-starter- web:$sprintBootVersion”) //正确
compile(‘org.springframework.boot:spring-boot-starter-thymeleaf:$sprintBootVersion’) //错误
}

    原文作者:苗喵秒
    原文地址: https://www.jianshu.com/p/e2061d0ac986
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞