How do I get build.gradle to leave .class files in the build/classes directory?

How do I get build.gradle to leave .class files in the project_loc/build/classes directory?

Eclipse generates .class files and puts them (along with resources) into the project_loc/bin/test direcotory but I can’t figure out why Gradle won’t do similar.

My project_loc/build/classes directory is ALWAYS empty.

When I try to run my project from gradle.bat , I always get tons of errors ( as if gradle can’t find its own “Gradle Dependencies” directory) but the project runs fine on a JUnit Eclipse run configuration.

You can see my project source code at: https://github.com/djangofan/WebDriverTestingTemplate

Any ideas on what I am doing wrong? I have a feeling it is something really basic.

// build.gradle
apply plugin: 'java'
apply plugin: 'eclipse'
  sourceCompatibility = 1.6
version = '1.0.0'
  repositories {
    mavenCentral()
    maven {
        url "http://maven2.javacpp.googlecode.com/git/"
    }
    maven {
        url "http://maven2.javacv.googlecode.com/git/"
    }
}
  dependencies {
    // stored at: %HOMEPATH%/.gradle/caches/artifacts-14/filestore
    testCompile group: 'org.sikuli', name: 'sikuli-api', version: '1.0.+'
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    testCompile group: 'junit', name: 'junit', version: '4.+'
    testCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.+'
}
  test {
    systemProperties 'BROWSER': 'firefox'
}

This is the kind of error I get when I try to compile from Gradle:

C:\Eclipse32\workspace\WebDriverTestingTemplate>gradle classes --stacktrace
:compileJava
C:\Eclipse32\workspace\WebDriverTestingTemplate\src\main\java\test\webdriver\ExtendedUtilities.java:5: package org.openqa.selenium does not exist
import org.openqa.selenium.By;
                          ^
C:\Eclipse32\workspace\WebDriverTestingTemplate\src\main\java\test\webdriver\ExtendedUtilities.java:6: package org.openqa.selenium does not exist
import org.openqa.selenium.Keys;

I suspect that I need some kind of build.gradle code to tell the gradle compiler where to find “Gradle Dependencies” so that the .class files can be successfully built?

seems that you havn’t declared all your thirdparty dependencies. In this particular case I think selenium-commons is missing to get your code compiled.

cheers, René

Ok, I figured it out.

I didn’t think I would figure it out.

I needed to change my dependencies like this:

dependencies {
    // stored at: %HOMEPATH%/.gradle/caches/artifacts-14/filestore
    compile group: 'org.sikuli', name: 'sikuli-api', version: '1.0.+'
    compile group: 'junit', name: 'junit', version: '4.+'
    compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.+'
    compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
    testCompile group: 'org.sikuli', name: 'sikuli-api', version: '1.0.+'
    testCompile group: 'junit', name: 'junit', version: '4.+'
    testCompile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '2.+'
    testCompile group: 'commons-collections', name: 'commons-collections', version: '3.2'
}

What I ran into was a problem of having some of my classes in the main java dir as well as the test java dir and so I had to add dependencies that were reachable by both of those codebases (see above).

Everything that’s on ‘compile’ automatically goes on ‘testCompile’. Also, ‘junit’ and ‘selenium’ should probably only be added to ‘testCompile’, because production code typically won’t need them.

I didn’t know that. Thanks for the tip.