Proper technique for copying resources for tests in custom tasks

I’m working on a custom Gradle plugin to replace a Maven plugin, along with a Gradle build to replace the Maven build.

The custom plugin reads text files in a particular language and generates Java source from those files that are later compiled. It also puts the auxiliary files that were read into a META-INF folder in the resulting jar file.

When I looked at what the Maven plugin was doing, I saw that it was writing the text files into “target/classes/META-INF/…”. At first I didn’t think this was necessary, because I just thought these files were needed at runtime. However, I’m now realizing that these files are also read by integration tests, which don’t have the resulting jar in the classpath.

So, I assume that I’m going to have to change my custom task to write those source files to “build/classes/META-INF/…”. First, is this the best place to put these files, so that the tests will have them in the classpath? Second, what is the best API and convention to use in the custom task to make this happen?

I would just have your plugin configure the ‘processResources’ task to accomplish this.

processResources {
    from('src/text') {
        into 'META-INF'
    }
}

Ok, I believe the following is now doing what’s required:

ProcessResources    processResourcesTask = project.processResources
processResourcesTask.from(task.yangFilesRootDir) { into(META_INF_YANG) }

(In the forum, what should I use to format code blocks? The “Blockquote” or the “Preformatted text”? The latter makes it come out weird.)

Preformatted text. Alternatively the markdown style (4 space indent) does the same.

Yeah. That isn’t working, assuming what I see in the preview represents what I should see in the final posting.

I’m pasting a short block of code that I’m attempting to post into another note. I first indented each line by 4 spaces in an external editor. This practice is annoying, but it works in SO, which is a similar forum. What I see in preview is that the first line is in a code font and with a grey background, but everything else after it is in the normal font, without the grey background.

After posting this, I see that it does show up correctly, and while I’m re-editing this after seeing the initial posting, it’s also showing up correctly. It appears that the initial display in preview is incorrect.

include ':toaster'
include ':toaster-config'
include ':toaster-consumer'
include ':toaster-provider'
include ':toaster-it'
include ':clustering-testapp:configuration'
include ':clustering-testapp:model'
include ':clustering-testapp:provider'

// Change project name so archive name matches maven build.
// Unfortunately, this can't be done (yet) in the subproject build.gradle file.
project(":toaster").name                = "sample-toaster"
project(":clustering-testapp:configuration").name    = "clustering-it-config"