Itiviti / gradle-nuget-plugin

Executes NuGet from a gradle build
Apache License 2.0
22 stars 29 forks source link

Declare list of files in nuspec programatically #7

Closed dustinstanley closed 9 years ago

dustinstanley commented 9 years ago

Is this behavior supported? I'd like to automatically declare all files in a specific directory without having to list each specific one, e.g.

    delegate.files {
        fileTree(msbuild.destinationDir).each { File entry ->
            delegate.file(src: entry, target: 'lib')
        }
    }

When I do this, I get the error below. Using delegate.file on the same files outside the above closure works fine, however.

Caused by: org.gradle.internal.typeconversion.UnsupportedNotationException: Cannot convert the provided notation to a File or URI: {src=build\msbuild\bin\log4net.dll, target=lib}. The following types/formats are supported:

gluck commented 9 years ago

delegate is an implicit variable scoped to the current closure.

Writing:

nuspec { delegate.foo() }

is the same as

nuspec { foo() }

but being explicit about the fact that you want to use the method resolving on the XMLBuilder (that is the XML building DSL).

This is needed as gradle scripts already define some methods (file/files) that'll be called otherwise as they're part of any script scope.

In your case as you got out of the XMLBuilder closure (you're in the each) closure, the XMLBuilder delegate is no longer available and your stack show that you use Script.file instead of XMLBuilder.file.

Try this instead:

delegate.files {
    def filesXmlNode = delegate;
    fileTree(msbuild.destinationDir).each { File entry ->
        filesXmlNode.file(src: entry, target: 'lib')
    }
}

Should work I think.

dustinstanley commented 9 years ago

Thanks for the explanation! That worked nicely. I will close this issue.