繁体   English   中英

Gradle Package 不存在

[英]Gradle Package does not exist

I am trying to build Gradle using ./gradlew build but during compilation getting following error package not found.In eclipse I am able to run refresh gradle but in command prompt facing the below issue:

        > 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映射的dependencies项将使用src/test/java类进行编译
  2. 使用compile映射的dependencies项将使用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'

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM