Max
Max

Reputation: 5081

How to copy file from buildSrc into main build

I have a custom task in buildSrc that, among other things, I want to copy a file from buildSrc into the main build. However, when actually running the custom task, the buildSrc project appears to be pretty much invisible, e.g. I can't reference it as a project. How does one refer to and copy a file from the buildSrc project to the main project?

Upvotes: 1

Views: 505

Answers (1)

cmcginty
cmcginty

Reputation: 117028

You are correct that the main projects can not see buildSrc. buildSrc is run as a separate project.

The outputs of buildSrc project are put onto the classpath of the main Gradle projects.

One solution then is to generate a Jar artifact with all of your resources, and then use the classpath resource loader in the main projects to access the files you need.

A second option might be to just manually hard code the buildSrc path into your main projects. Of course you can not access it as project(:buildSrc') because it is not valid. The better option is to use file("${rootProject}/buildSrc/") (Not tested).

Upvotes: 1

Related Questions