Is there a way to have a standalone plugin behave as buildSrc during development?

I’ve been working on a custom Gradle plugin. At first, I was developing it in the buildSrc directory, and everything was great.

Now I’m working on making it standalone and am frustrated at the extra steps involved. I have to install the plugin ahead of time, then run the code that executes it. What was a one step process is now a two step process, which makes development more laborious.

I tried creating a symlink from the plugin directory to buildSrc but that ran into some bizarre issues with closures not working.

Is there a better solution to this problem?

Your other option would be to use the Tooling API to run integration tests inside your project.

I’m not familiar with the Tooling API so let me clarify - this would basically be a meta-project that can both create the plugin then run tests against the project I want to apply it to?

Also, it seems like normal plugin tests could help cover a lot of the development, but I’m having issues with how to get the project’s projectDir/buildDir from it… is there any way to get the Project that built the tests?

I’m not sure exactly what you mean by that. If you want access to the Gradle build that is building your tests from the test itself that isn’t possible. I’m also not sure why you’d want to do that. Want information do you need exactly? Can you perhaps give an example of one of your test cases?

The plugin is converting files from SVG to PNG. In order to test it I want to feed it SVGs and then test that the output is correct. But if it creates a brand new project out in the middle of nowhere, I have difficulty in finding my way back to the test resources.

The typical way to do this is to create a temporary project directory in the build directory of your test project.

Sure, but my question is how do you get the build directory? There’s no project in the plugin test (that I know of) - that’s what I’m missing here.

The simplest implementation is just to create a new ‘File’ with a relative path. Although this is not explicitly reliable, it’s not particularly important where this temporary directory goes. In this case it would be relative to the working dir, which in a typical Gradle build is the project directory.

new File(‘build/testDir’)