简体   繁体   中英

How do i fix my dependencies in my build.gradle file

I am new to gradle, i need to configure my build.gradle file . Am using selenium webdriver and i have list of .jar files. how do i include this jar files as dependencies in my build.gradle file?. i have this .jar in a folder called lib in my package. and i have

dependencies {
compile fileTree(dir: 'lib', includes: '*.jar')    

} but i keep having the error below:

FAILURE: Build failed with an exception.

Where:Build file '/home/ola/workspace/build.gradle' line: 20

What went wrong: A problem occurred evaluating root project 'workspace'. Cannot cast object '*.jar' with class 'java.lang.String' to class 'java.lang.Iterable'

please can anyone point me to how to write dependencies for a webdriver project using gradle.This is the path to my lib folder: "/home/user/workspace/mainsite_automation/src/autoTest/lib/"

Thanks

You just need to specify the dependencies repository and the selenium webdriver dependencies so you will end up with a build.gradle similar to this:

apply plugin: 'java'
apply plugin: 'jetty'

repositories {
    mavenCentral()
}

sourceSets {
    selenium
}

dependencies {
    seleniumCompile 'junit:junit:4.11'
    seleniumCompile 'org.seleniumhq.selenium:selenium-java:2.30.0'
}

task jettyDaemon(type: org.gradle.api.plugins.jetty.JettyRun) {
    daemon = true
}

task selenium(type: Test, dependsOn: jettyDaemon) {
    testClassesDir = sourceSets.selenium.output.classesDir
    classpath = sourceSets.selenium.runtimeClasspath
}

for Eclipse, you can add selenium dependencies to the classpath adding this to your build.gradle:

eclipse {
    classpath {
        plusConfigurations += configurations.seleniumCompile
    }
}

then you can use grade clean selenium to rebuild your project.

Sources:

https://docs.gradle.org/current/userguide/artifact_dependencies_tutorial.html http://www.dreamchain.com/gradle-selenium-webdriver-task/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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