Why this gradle build script is not compiling java class?

Shekhar picture Shekhar · Sep 11, 2013 · Viewed 7.2k times · Source

I am trying to use Cascading in my Hadoop project. I am trying to implement first example given in Enterprise Data Workflows with Cascading book. I have written java class which contains Cascading related code and I have another build.graddle file which is supposed to compile that java class and build jar file out of it.

My folder structure is as follows :

  • main_folder

    • impatient

      • Main.java
      • build.gradle

My build.gradle file looks as below :

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'eclipse'

archivesBaseName = 'impatient'
repositories {
    mavenLocal()
    mavenCentral()
    mavenRepo name: 'conjars', url: 'http://conjars.org/repo/'
}
ext.cascadingVersion = '2.1.0'
dependencies {
    compile( group: 'cascading', name: 'cascading-core', version: cascadingVersion )
    compile( group: 'cascading', name: 'cascading-hadoop', version: cascadingVersion )
}
jar {
    description = "Assembles a Hadoop ready jar file"
    doFirst {
        into( 'lib' ) {
            from configurations.compile
        }
    }
    manifest {
        attributes( "Main-Class": "impatient/Main" )
    }
}

When I run gradle clean jar command from command prompt, I get build successful message. I tried to run this jar file using

hadoop jar impatient.jar <input file path> <output file path>

command but then it gives me Exception in thread "main" java.lang.ClassNotFoundException: impatient.Main exception.

So I checked contentes of jar file and found that that jar does not contain impatient/Main.class file.

Please note that I do not know anything about gradle.

Request someone to please tell me if there is anything wrong with gradle script or I am making some mistake.

Thanks !!!

Answer

Nikita Skvortsov picture Nikita Skvortsov · Sep 13, 2013

Move your source file to

main_folder/impatient/src/main/java/Main.java

but leave build.gradle file where it is.

By default, Gradle uses src/main/java and src/test/java to look for production and test java sources (relative to root folder, which is impatient in your case)