「Apache Groovy」- Grape,依赖管理工具(学习笔记) @20210204

问题描述

Grape,是 Groovy 的依赖管理工具,可以让我们快速添加 Maven 依赖,简化脚本的编写。

该笔记将记录:在 Groovy 中,如何使用 Grape 管理依赖,以及常见问题处理。

解决方法

在代码中,引入依赖:

@Grab(group='org.springframework', module='spring-orm', version='3.2.5.RELEASE')
import org.springframework.jdbc.core.JdbcTemplate

// 或者,使用简写
@Grab('org.springframework:spring-orm:3.2.5.RELEASE')
import org.springframework.jdbc.core.JdbcTemplate

常见问题汇总

使用其他仓库

@GrabResolver(name='custom', root='http://customserver/repo', m2Compatible='true')
@Grab('com.mrhaki:groovy-samples:1.0')
import com.mrhaki.groovy.Sample
 
def s = new Sample()
s.justToShowGrabResolver()  // Just a sample

如下示例,在 Groovy 中,使用阿里云镜像仓库:

@Grapes([
    @GrabResolver(name='aliyun', root='https://maven.aliyun.com/repository/central', m2Compatible='true'),
    @Grab(group='org.xerial',module='sqlite-jdbc',version='3.7.2'),
    @GrabConfig(systemClassLoader=true)
])

调试下载过程(调试信息)

在安装扩展的过程中,我们希望显示扩展的下载信息,以了解下载进度,判断下载是否阻塞。此时,可以增加调试级别:

groovy -Divy.message.logger.level=4 -Dgroovy.grape.report.downloads=true example.groovy

// 或者,使用环境变量

export JAVA_OPTS="$JAVA_OPTS "'-Divy.message.logger.level=4 -Dgroovy.grape.report.downloads=true'

通过代理进行下载

groovy -Dhttp.proxyHost=yourproxy -Dhttp.proxyPort=8080 yourscript.groovy

// 或者,使用环境变量

export JAVA_OPTS="$JAVA_OPTS "'-Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8123 -Dhttps.proxyHost=127.0.0.1 -Dhttps.proxyPort=8123'

参考文献

WikiNotes/Grape,依赖管理工具(学习笔记)
Dependency management with Grape
groovy grape verbose
Groovy Goodness: Use GrabResolver for Custom Repositories

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值