经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 软件/图像 » Gradle » 查看文章
Gradle之FTP文件下载
来源:cnblogs  作者:一翼诚  时间:2019/9/11 8:52:16  对本文有异议

Gradle之FTP文件下载

1、背景

项目上需要使用本地web,所以我们直接将web直接放入assets资源文件夹下。但是随着开发进行web包越来越大;所以我们想着从版本库里面去掉web将其忽略掉,使用gradle命令下载web。由于web包是放在局域网服务器上的,服务器支持FTP文件协议,所以使用FTP插件下载文件。

2、FTP

FTP官网文档

Gradle官网文档
gradle配置

3、FTP工具

ftp-util.gradle

  1. configurations {
  2. ftpAntTask
  3. }
  4. dependencies {
  5. ftpAntTask("org.apache.ant:ant-commons-net:1.9.2") {
  6. module("commons-net:commons-net:3.3")
  7. }
  8. }
  9. void downloadFtpFiles(String serverIp, String userId, String password, String url, localDir) {
  10. ant.taskdef(
  11. name: 'ftp',
  12. classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
  13. classpath: configurations.ftpAntTask.asPath
  14. )
  15. //指定ftp地址及账户信息
  16. ant.ftp(action: 'get', server: serverIp, userid: userId, password: password, remotedir: url) {
  17. // 删除老文件
  18. delete(new File(localDir))
  19. //指定下载文件位置
  20. fileset(dir: new File(localDir)) {
  21. include(name: "**")
  22. }
  23. }
  24. }
  25. //导出函数
  26. ext {
  27. downloadFtpFiles = this.&downloadFtpFiles
  28. }

使用方式:

导入方式:将ftp-util.gradle文件放在根目录下然后使用一下代码导入groovy代码

  1. apply from: "${project.rootProject.file('ftp-util.gradle')}"

下载任务

  1. task downloadFiles() {
  2. //清理缓存
  3. dependsOn 'clean'
  4. def dir = buildDir.getPath() + '/dir'
  5. doLast {
  6. //获取最新版本信息
  7. ant {
  8. println 'web-ftp:serverIp:' + serverIp
  9. println 'web-ftp:userId:' + userId
  10. println 'web-ftp:password:' + password
  11. println 'web-ftp:dir:' + dir
  12. println 'web-ftp:sync start'
  13. def url = webUrl + '/latest'
  14. //调用FTP插件下载文件函数
  15. downloadFtpFiles(serverIp, userId, password, url, dir)
  16. println 'web-ftp:sync end'
  17. }
  18. }
  19. }

调用task方式

  1. ./gradlew downloadFiles

原文链接:http://www.cnblogs.com/hejing-michael/p/gradle-zhiftp-wen-jian-xia-zai.html

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号