Jar file dependency not working inside buildscript body

I can’t seem to find classes in a jar that I specify in the buildscript dependencies.

I have to build some java classes to use in build tasks so I need to use the buildscripts/buildSrc convention.

As a quick test, if I don’t use buildscripts and move my code from ./buildSrc/src to ./src, this build.gradle builds ok:

apply plugin: 'groovy'
repositories {
    mavenCentral()
}
dependencies {
    compile files('/opt/foo/format.jar')
       // these classes are found
}

However if I move the same source from ./src to buildSrc/src such that the groovy plugin tries to build it before running any tasks, it fails to find the classes in the above /opt/foo/format.jar

import com.foo.format.*
            // not sure if this is even needed, same behavior with & without
apply plugin: 'groovy'
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath files ('/opt/foo/format.jar')
     // these classes are not found
    }
}

%> gradle tasks :buildSrc:compileJava /home/bedge/foo/btest/buildSrc/src/main/java/com/foo/tools/tParser.java:26: error: package com.foo.format.folio does not exist import com.foo.format.folio.DefaultValidationEventHandler;

I did see a similar post, but it did not help with my situation as it stated this should just work. Maybe something has changed in the last year? (http://forums.gradle.org/gradle/topics/how_to_avoid_dependency_on_buildsrc_in_production_environment_and_specify_jar_file_with_compiled_files_on_the_buildscript_classpath)

Nothing has changed here over the last year. What exactly are you trying to achieve? Where do you put the code that uses ‘format.jar’, where do put the build script that declares the dependency on ‘format.jar’, and who uses the code? Did you try to put the first snippet into ‘buildSrc/build.gradle’?

Thanks again Peter, you solved my problem. I owe you a beer or 5. I wasn’t aware that buildSrc needed it’s own build.gradle file. That totally makes sense now and I see it in the docs (the part I hadn’t read…)