Gradle command-line not compiling code while plugin works fine


(Andrew Berman) #1

My Gradle project in Eclipse compiles fine with the Eclipse compile and Gradle plugin, however, when I run the gradle command-line, compilation is failing because it’s not finding classes that exist in the dependencies. I ran a gradle -q dependencies and it lists all the dependencies, but I’m baffled as to why it’s not compiling when it is working fine using the Eclipse plugin. I’m using the standard layout with absolutely nothing out of the ordinary (src/main/java and src/test/java). Does anyone have any thoughts?

Here is my build file (took out all the dependencies for brevity):

apply plugin: 'java'
  sourceCompatibility = '1.6'
targetCompatibility = '1.6'
  compileJava.options.encoding = 'ISO-8859-1'
  repositories {
    mavenCentral()
    maven {
        url "http://repo.springsource.org/release"
            }
}
  configurations {
    all*.exclude group: 'org.springframework', module: 'spring-dao'
    all*.exclude group: 'org.springframework', module: 'spring'
 }
  dependencies {
     compile (
...
    )
    runtime (
...
        )
    testCompile 'junit:junit:4.11'
}

(Peter Niederwieser) #2

It’s not an uncommon situation, and likely means that ‘compile’ doesn’t list all actual compile dependencies. This will go unnoticed in Eclipse because Eclipse doesn’t distinguish between compile, runtime, and other class paths.


(Andrew Berman) #3

Thanks for the reply, Peter! When I run a gradle dependencies, I do see all the dependencies under the “compile - Compile classpath for source set ‘main’,” “default - Configuration for default artifacts,” and “runtime - Runtime classpath for source set ‘main’” headings. Do I need to specify something in particular when running ‘gradle build’ to tell it to use the dependencies of source set ‘main’? I’m really baffled as to why this is not working. As you can see in my build, I’m doing nothing fancy. I’m just trying to get the code to compile (moving from ant to gradle).


(Andrew Berman) #4

I also just added this to my build and ran it and it listed all the proper dependencies:

task listJars << {
 configurations.compile.each { File file -> println file.name }
}

(Peter Niederwieser) #5

Assuming that the build fails during ‘compileJava’ (and not, say, ‘compileTestJava’):

task showCompileClasspath << {
    sourceSets.main.compileClasspath.each { println it }
}

Now verify that the missing classes are actually contained in one of the Jars, e.g. by listing Jar contents with ‘jar -tf some.jar’ (or with ‘zipTree(jarFile).each { println it }’ in Gradle). Chances are they aren’t. That’s all I can say, given the information you provided.


(Andrew Berman) #6

Ok, thanks Peter. I’m going to start with a new project and move over things one by one and see if I can get it to work.