Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add classpath entries so that buildSrc plugin can find my files in gradle?

Tags:

gradle

I have a gradle project, and am creating a custom plugin to do some extra build work. The source files for the plugin are stored in the buildSrc/. I have the basic skeleton working, and I can see the plugin tasks by running gradle tasks.

The problem I'm having is that I need to add project directories to the classpath for the plugin tasks.

I've tried adding the directories using the buildscript of my main build.gradle:

buildscript {
     repositories { mavenCentral() }
     dependencies { 
        classpath files('migrationScripts')
     }   
}

But this doesn't seem to have any impact on the classpath that the plugin sees. When I print out the classpath, I get the following:

/home/jharig/project/buildSrc/build/classes/main/
/home/jharig/project/buildSrc/build/resources/main/

How can I add

/home/jharig/project/migrationScripts

To the classpath when my plugin task executes?

Update: I don't want to declare the migrationScripts dependency in buildSrc/build.gradle.

like image 865
jharig23 Avatar asked Oct 02 '22 11:10

jharig23


1 Answers

You need to create buildSrc/build.gradle and declare /home/jharig/project/migrationScripts as a regular compile or runtime dependency. Note that this won't work if migrationScripts belongs to the same build as buildSrc, as all projects of a build effectively depend on buildSrc, and you can't have dependencies in both directions.

like image 63
Peter Niederwieser Avatar answered Oct 24 '22 02:10

Peter Niederwieser