• 使用groovy 下载maven依赖包


    主要集成了groovy的grape

    maven 依赖

    注意groovy的grape需要依赖apache ivy

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
     
        <groupId>org.example</groupId>
        <artifactId>mylocal-test</artifactId>
        <version>1.0-SNAPSHOT</version>
     
        <properties>
            <maven.compiler.source>11</maven.compiler.source>
            <maven.compiler.target>11</maven.compiler.target>
        </properties>
        <dependencies>
            <dependency>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy</artifactId>
                <version>3.0.8</version>
            </dependency>
            <dependency>
                <groupId>org.apache.ivy</groupId>
                <artifactId>ivy</artifactId>
                <version>2.5.0</version>
            </dependency>
        </dependencies>
     
    </project>

    参考代码

    private static void demoapp() {
            System.setProperty("grape.root", ".");
            Grape.setEnableAutoDownload(true);
            Grape.setEnableAutoDownload(true);
            Map<String, Object> param = new HashMap<>();
            GroovyClassLoader classLoader = new GroovyClassLoader();
            param.put("classLoader", classLoader); // 注意需要指定classloader
            param.put("group", "com.fasterxml.jackson.core");
            param.put("module", "jackson-databind"); // module 就是maven 的artifactId
            param.put("version", "2.12.5");
            // no need to download transitive dependencies as we only need to check the component itself
            param.put("validate", false);
            param.put("transitive", true);
            Grape.grab(param);
            Arrays.stream(Grape.listDependencies(classLoader)).forEach(new Consumer<Map>() {
                @Override
                public void accept(Map map) {
                    System.out.println(map.toString());
                }
            });
    }

    效果

    参考资料

    http://docs.groovy-lang.org/latest/html/documentation/grape.html

  • 相关阅读:
    Binding to a Service
    UML类图几种关系的总结
    阿里云调试
    Serif和Sans-serif字体的区别
    从Log4j迁移到LogBack的理由
    logback
    java 解析json格式数据(转)
    开源Web测试工具介绍
    GET乱码以及POST乱码的解决方法
    单元测试框架TestNg使用总结
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/15316483.html
Copyright © 2020-2023  润新知