java - Gradle 包不存在

标签 java gradle

我正在尝试使用 ./gradlew build 构建 Gradle,但在编译过程中出现以下错误:未找到包。在 Eclipse 中,我可以运行刷新 gradle,但在命令提示符下面临以下问题:

        > Task :compileJava FAILED
    /Users/Documents/em-cedm-integ-test/src/main/java/com/BaseTest.java:3: error: package io.restassured does not exist
    import static io.restassured.RestAssured.given;
                                ^
     /Users/Documents/em-cedm-integ-test/src/main/java/com/BaseTest.java:3: error: static import only from classes and interfaces
    import static io.restassured.RestAssured.given;
    ^
     /Users/Documents/em-cedm-integ-test/src/main/java/com/BaseTest.java:21: error: package org.apache.commons.lang3 does not exist
    import org.apache.commons.lang3.StringUtils;
                                   ^
     /Users/Documents/em-cedm-integ-test/src/main/java/com/BaseTest.java:34: error: package io.restassured.response does not exist
    import io.restassured.response.ExtractableResponse;
                                  ^
     /Users/Documents/em-cedm-integ-test/src/main/java/com/BaseTest.java:35: error: package io.restassured.response does not exist
    import io.restassured.response.Response;
                                  ^
     /Users/Documents/em-cedm-integ-test/src/main/java/com/CedmTest.java:3: error: package org.junit.runner does not exist
    import org.junit.runner.JUnitCore;
                           ^
                           ^

我正在使用的Build.gradle文件

// Apply the java-library plugin to add support for Java Library

apply plugin: 'java'

allprojects {

    repositories {

        // You can declare any Maven/Ivy/file repository here.
       maven {
                url "http://repo.hortonworks.com/content/repositories/releases"
            }

       maven {
                url "${artifactory_contextUrl}"
                credentials {
                    username = "${artifactory_user}"
                    password = "${artifactory_password}"
                }
            }

        maven {
                url "${artifactory_contextUrl}/ip-fci-maven-virtual"
                credentials {
                    username = "${artifactory_user}"
                    password = "${artifactory_password}"
                }
            }

    }

    configurations.all { 
        transitive = false
    }
}



version = '1.0'
task fatJar(type: Jar) {
    manifest {
        attributes 'Implementation-Title': 'Gradle Jar File Example',  
            'Implementation-Version': version,
            'Main-Class': 'com.ibm.cedm.CedmTest'
    }
    baseName = project.name + '-all'
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
    with jar
}


defaultTasks 'downloadFile'
dependencies {

    compile group: 'com.google.guava', name: 'guava', version: '12.0.1'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.9.7'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.7'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.9.7'
    compile group: 'org.apache.kafka', name: 'kafka-clients', version: '0.11.0.3'
    compile group: 'org.apache.hbase', name: 'hbase-client', version: '1.1.2.2.6.4.0-91'
    compile group: 'org.apache.hbase', name: 'hbase-common', version: '1.1.2.2.6.4.0-91'
    compile group: 'org.apache.hbase', name: 'hbase-client', version: '1.1.2.2.6.4.0-91'
    compile group: 'org.apache.hadoop', name: 'hadoop-common', version: '2.7.3.2.6.4.0-91'
    compile group: 'com.tdunning', name: 'json', version: '1.8'
    compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
    compile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.10'
    compile group: 'org.apache.oozie', name: 'oozie-client', version: '4.2.0'  
    compileOnly group: 'io.swagger', name: 'swagger-annotations', version: '1.5.12'
    compileOnly group: 'javax', name: 'javaee-api', version: '7.0'
    compile group: 'ip-fci-generic-local.fcco-core', name: 'fci-core-utils', version: 'master'
    compile(group: 'ip-fci-generic-local.media', name: 'db2jcc4', version: '11.1.3')



    testImplementation 'junit:junit:4.12'

    testCompile group: 'commons-codec', name: 'commons-codec', version: '1.9'
    testCompile group: 'com.tdunning', name: 'json', version: '1.8'
    testCompile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.6'
    testCompile group: 'org.apache.httpcomponents', name: 'httpmime', version: '4.5.6'
    testCompile group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.10'
    testCompile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'
    testCompile group: 'commons-logging', name: 'commons-logging', version: '1.2'
    testCompile group: 'io.rest-assured', name: 'rest-assured', version: '3.0.2'
    testCompile group: 'io.rest-assured', name: 'rest-assured-common', version: '3.0.2'
    testCompile group: 'io.rest-assured', name: 'json-path', version: '3.0.2'
    testCompile group: 'io.rest-assured', name: 'xml-path', version: '3.0.2'
    testCompile group: 'net.javacrumbs.json-unit', name: 'json-unit', version: '1.5.2'
    testCompile group: 'net.javacrumbs.json-unit', name: 'json-unit-core', version: '1.5.2'
    testCompile group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3'
    testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
    testCompile group: 'org.codehaus.groovy', name: 'groovy', version: '2.4.4'
    testCompile group: 'org.codehaus.groovy', name: 'groovy-json', version: '2.4.4'
    testCompile group: 'org.slf4j', name: 'slf4j-api', version: '1.7.25'
    testCompile group: 'org.slf4j', name: 'slf4j-jdk14', version: '1.7.25'

}

/*
test {
    filter {
        //include specific method in any of the tests
        includeTestsMatching "*createBasicIndividualParty"

    }
}
*/

有人可以告诉我为什么会这样吗?我应该做出哪些改变才能使其发挥作用?

最佳答案

如何映射依赖关系

  1. 使用 testCompile 映射的依赖项将使用 src/test/java 类进行编译
  2. 使用 compile 映射的依赖项将使用 src/main/java 类进行编译

gradle 配置问题

很少有依赖项被映射为 testCompile,但可以在生产代码 src/main/java 中引用它。

testCompile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'

应该是

compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.3.2'

关于java - Gradle 包不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58331257/

相关文章:

java - 可运行的导出 JAR 在退出 Eclipse 时未正常运行

Java运行时执行

android - 如何在 Android Studio 中构建旧的 Android 项目

android - Gradle 执行 dex 错误命令行太长

android - jniLibs 未在 gradle 中扩展

java - 追加数组

java - 在 Android 中等待多个回调

java - JavaFX 中的 Hibernate - 显示来自所选 ID 的记录

gradle - 403您无权执行促销 'snapshotToRelease'

java - 从 jar 启动时,由 gradle 构建的嵌入式 jetty 应用程序始终返回 500(内部服务器错误)