0

我正在尝试使用 java 依赖项创建一个 groovy 库(JAR),但没有成功。我设法使用简单的方法,但是当我的代码使用第三方库时,它不会找到相关的类。

摇篮版本:5.2

Groovy 1.8.9

项目结构:

在此处输入图像描述

构建.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'

MyClassWithDependencies:

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 依赖项是(我想这里的图片是最好的选择):

在此处输入图像描述

任何帮助将非常感激。提前致谢。

PS我设法创建了一个Fat Jar,但这不是我需要的。

4

0 回答 0