1

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

Joe
  • 147
  • 1
  • 4
  • 17

1 Answers1

1

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/

NotGaeL
  • 8,344
  • 5
  • 40
  • 70
  • is this correct?. this is what i have at the begging of my build file: _apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'application'_ – Joe Apr 04 '16 at 13:16
  • ok. also should there be a particular path for my project or it does not matter? At the moment, this is my path _/home/ola/workspace/mainsite_automation/src/autoTest/_ and inside the autoTest i have 3 packages, functional, API and lib – Joe Apr 04 '16 at 13:18
  • This works fine and my BUILD was Successful. Please do i need to add the wrapper so as to add it to source control (Jenkins). The purpose of me using this build tool is to integrate my project with Jenkins.Please where do i go from here? Here is my wrapper : _task wrapper(type: Wrapper) { gradleVersion = '2.3' }_ – Joe Apr 04 '16 at 13:28
  • 1
    there is a predefine directory structure. You can use `gradle init` to create that structure. For the java plugin check out https://docs.gradle.org/current/userguide/java_plugin.html#tab:configurations For selenium tests are expected in `src/selenium/java` (see http://www.dreamchain.com/gradle-selenium-webdriver-task/ ). For more info: http://stackoverflow.com/questions/14017364/how-to-create-java-gradle-project – NotGaeL Apr 04 '16 at 13:30
  • 1
    Thanks so much for your help...... AM so grateful. well, i ran gradle build and gradle wrapper and all seems to build correctly. dont know why but will create a new project like you said and have it in the right format as suggested. i will let you know my outcome. – Joe Apr 04 '16 at 13:35
  • 1
    It is very easy to run gradle on jenkins. You can add gradle plugin to jenkins and then set jenkins to use gradle wrapper. You can also run gradle wrapper and check out the generated sources into the repo jenkins will build the project from. Check http://stackoverflow.com/questions/8646762/cannot-run-program-gradle-in-jenkins if you have any trouble setting it up. – NotGaeL Apr 04 '16 at 13:35
  • gradle init generated a structure for me but here is my question, which call goes into the src.main.java and which class goes into src.test.java. In my current project, i have 2 packages, one with my method class and main class while the other has API in it.... which goes in main and which in test. – Joe Apr 04 '16 at 14:52
  • src/main/java -> application code: this code is what you actually need to run the application; src/test/java -> unit tests (like junit tests and so on): this code is for automated testing (of the code in src/main/java) purposes only – NotGaeL Apr 04 '16 at 16:30