代码之家  ›  专栏  ›  技术社区  ›  rodridevops

Gradle-创建带有Java依赖项的定制Groovy库(apachecommons)

  •  0
  • rodridevops  · 技术社区  · 6 年前

    Gradle版本:5.2

    项目结构:

    enter image description here

    生成.gradle

    /*
     * This file was generated by the Gradle 'init' task.
     *
     * This generated file contains a sample Groovy project to get you started.
     * For more details take a look at the Groovy Quickstart chapter in the Gradle
     * User Manual available at https://docs.gradle.org/5.2/userguide/tutorial_groovy_projects.html
     */
    
    plugins {
        // Apply the groovy plugin to add support for Groovy
        id 'groovy'
    }
    
    repositories {
        // Use jcenter for resolving your dependencies.
        // You can declare any Maven/Ivy/file repository here.
        jcenter()
    }
    
    dependencies {
        // Use the latest Groovy version for building this library
        implementation 'org.codehaus.groovy:groovy-all:1.8.8'
        compile  group: 'com.google.code.gson', name: 'gson', version: '2.2.4'
        compile  group: 'commons-io', name: 'commons-io', version: '2.6'
    
       // https://mvnrepository.com/artifact/org.spockframework/spock-core
        testCompile group: 'org.spockframework', name: 'spock-core', version: '1.1-groovy-2.4'
    
    }
    

    设置.gradle

    /*
     * This file was generated by the Gradle 'init' task.
     *
     * The settings file is used to specify which projects to include in your build.
     *
     * Detailed information about configuring a multi-project build in Gradle can be found
     * in the user manual at https://docs.gradle.org/5.2/userguide/multi_project_builds.html
     */
    
    rootProject.name = 'com.itau.plugins'
    

    package com.itau.plugins
    
    import org.apache.commons.io.FileUtils
    
    
    class MyClassWithDependencies {
    
        def copy(source, destination) {
            FileUtils.copyFile(new File(source), new File(destination))
        }
    
        def copyDir(source, destination) {
            FileUtils.copyDirectory(new File(source), new File(destination))
        }
    
    }
    

    错误很明显:

    Groovy:unable to resolve class org.apache.commons.io.FileUtils

    当我跑的时候 gradlew build --no-build-cache

    BUILD SUCCESSFUL in 1s                                                                                                                                                                                  
    2 actionable tasks: 2 up-to-date   
    

    我对gradle的依赖性是(我想这里最好的选择是一张照片):

    enter image description here

    任何帮助都将不胜感激。提前谢谢。

    0 回复  |  直到 6 年前