Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use classes compiled by Gradle buildSrc in main Groovy project?

Classes compiled by buildSrc/build.gradle are not resolved at runtime when they are used in main PROJECT classes.

My Groovy project structure looks like this:
-PROJECT
    -buildSrc/
        -build.gradle
        -/src/main/groovy
            - com.company.global.test.report
    -src/test/groovy
    -build.gradle

Is there something I can add to the top-level PROJECT/build.gradle to allow the classes compiled by it to use the classes compiled by buildSrc/build.gradle?

like image 337
XDelphiGrl Avatar asked Apr 10 '13 15:04

XDelphiGrl


People also ask

What is buildSrc in Gradle?

What is buildSrc. buildSrc is a directory at the Gradle project root, which can contain our build logic. This allows us to use the Kotlin DSL to write our custom build code with very little configuration and share this logic across the whole project.

Is Gradle using Groovy?

gradle is a Groovy script. Thus it can execute arbitrary code and access any Java library, build-specific Gradle DSL and the Gradle API.


1 Answers

buildSrc is its own build (not project) that gets executed before the main build. Its sole purpose is to make some classes (plugins, tasks, regular classes) available to the build scripts of the main build. Hence you could call it a "meta-build".

Technically, it would be possible to add the compiled classes of buildSrc to the compile or runtime class path of a project in the main build, but I don't recommend to do it. There is very likely a better way to achieve your goals (but I don't know what those are).

like image 177
Peter Niederwieser Avatar answered Oct 18 '22 03:10

Peter Niederwieser