本人在使用Jenkins作测试项目的可持续集成过程当中,构建工具用的gradle,但因为一些jar包是并私有仓库给用,暂时没有搭建计划。这就致使了我构建项目的时候须要的jar的地址每每是不同的,并且服务器和本地的版本可能也有所差异,常常其余同窗提交代码时候把build.gradle文件一并提交了,却是仓库文件比较乱。为了解决这个问题,看了一些资料再研究了一点点gradle的使用后总结了两种方法。java
第一种思路:把每一个人的项目依赖的jar包地址给固定了,而后用判断当前用户是哪一个,再去给complie files参数赋值。比较笨,可是比较容易理解,因为框架的jar包和一些固定的jar包版本不怎么发生变化,维护成本较低。也是我这个菜鸟想到的第一个办法,虽然已经不用了,仍是记录一下比较好web
第二种思路:每次去局域网服务器下载jar包,比对版本,若是同样则下载到项目的文件夹里,再去给complie files参数赋值。这个比较简单,并且可以作到jar包版本更新的时候自动同步(服务端的jar有Jenkins生成)。暂时想到的比较好的办法。spring
分享一下代码,供你们参考:apache
buildscript { ext { springBootVersion = '1.5.13.RELEASE' } repositories { mavenLocal() mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'idea' apply plugin: 'org.springframework.boot' apply plugin: 'io.spring.dependency-management' group = 'com.fission.test' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenLocal() mavenCentral() } def jarversion = "api_test_najm-1.0-SNAPSHOT.jar" def path = getPath2(jarversion) def getPath() { def local; File file1 = new File("/Users/Vicky/Documents/workspace/api_test_najm/build/libs/api_test_najm-1.0-SNAPSHOT.jar") File file2 = new File("/go/jar/api_test_najm-1.0-SNAPSHOT.jar") if (file1.exists()) { local = file1.getAbsoluteFile() } else if (file2.exists()) { local = file2.getAbsoluteFile() } println local return local } def getPath2(String v) { def jarpath = new File("").getAbsolutePath() + "/long/" + v if (new File(jarpath).exists()) return jarpath def url = new URL("http://**.***.**.**:****/go/jar/" + v) def out = new FileOutputStream(jarpath) out << url.newInputStream() return jarpath } dependencies { runtime('org.springframework.boot:spring-boot-devtools') compile('org.springframework.boot:spring-boot-starter-web') testCompile('org.springframework.boot:spring-boot-starter-test') compile "org.springframework.boot:spring-boot-starter-thymeleaf" compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0' compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0' compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.8.0-beta2' compile files(path) }
因为以前接触过groovy语言,写起了也很是顺手,先简单写个例子。之后有机会继续分享gradle自定义脚本任务和Jenkins集成的实践经验。编程