首页 > 解决方案 > Gradle 包不存在

问题描述

我正在尝试使用./gradlew build构建 Gradle,但在编译过程中找不到以下错误包。在 eclipse 中,我能够运行 refresh 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"

    }
}
*/

有人可以告诉我为什么会这样吗?我应该进行哪些更改才能使其正常工作?

标签: javagradle

解决方案


依赖关系如何映射

  1. dependencies映射的testCompile将与src/test/java类一起编译
  2. dependencies映射的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'

推荐阅读