Gradle Selenium (WebDriver) task

If you want to run your Selenium (WebDriver) tests from Gradle you can do it like this:

1. Add Jetty plugin to build.gradle:

apply plugin: 'jetty'

2. Create a src/selenium/java folder in you project root.

3. Add a SourceSet to build.gradle:

sourceSets {
    selenium
}

4. Add Selenium dependencies to build.gradle:

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

Add jettyDaemon and selenium tasks to build.gradle:

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
}

5. If you are using Eclipse, add Selenium dependencies to the Eclipse classpath in build.gradle:

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

You can now place you Selenium tests in src/selenium/java and run:

gradle clean selenium

MacPorts, Clojure and ClassNotFoundException

After installing Clojure with MacPorts I got the following exception when running a basic Clojure script:

Exception in thread "main" java.lang.NoClassDefFoundError: Pad:/opt/local/share/java/clojure/bin////lib/clojure/jar
Caused by: java.lang.ClassNotFoundException: Pad:.opt.local.share.java.clojure.bin....lib.clojure.jar
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

As it turned out, I had run the script from a folder with a space in it’s name, “Scratch Pad”. After moving the script to an other folder, the script ran just fine.