Copy within a plugin?

I want to copy stuff from my compiled dependencies. When I try to do that from my main build script, it works fine.

task copyStuff(type: Copy) {
    from (configurations.compile) {
        include "*.nar"
    into "${buildDir}/nar/download"

However, within a plugin it doesn’t work. By simply copying the above code into the apply{} block and preceding it with a “project.” it gives me the error that it doesn’t know what “Copy” is. When I also try to import “org.gradle.api.tasks.Copy”, all error messages disappear, but nothing happens in terms of actually copying.

project.task('copyStuff', type: Copy) {
    from (project.configurations.compile) {
        include "*.nar"
    into "${project.buildDir}/nar/download"

Anything I’m missing here?

Can you double check that the task is executing? Is it being skipped or marked as up-to-date?

All you’re doing is declaring a task there. If nothing depends on that task, it will never execute.

It’s marked up-to-date.

But I’m directly executing the task (“gradle copyStuff”). With any normal plugin task that doesn’t have a “type” attribute, everything works fine.

please run the build again with the -i flag. that usually gives you a hint why gradle consideres this task of being up-to-date.

Skipping task ':copyStuff' as it has no source files.
:copyStuff UP-TO-DATE

I… What? Why is this happening? Literally all I need to do is to attach a “type” to my task and suddenly it’s getting skipped due to no apparent source file.