Trying to wire custom task to artifact, but "Cannot convert the provided notation"

(Dan Gravell) #1

I have a custom task that produces a file, and I’m trying to declare this as an artifact. Here’s my custom task:

class ConcatFiles extends DefaultTask {
    FileCollection files
    File target
    void concat() {
        files.each { file ->

task buildWindowsInstaller(type: ConcatFiles) {
	files = files('src/installer/native/7zS.sfx', 'src/installer/native/config.txt', build7zaArchive)
    target = file("$buildDir/distributions/setup.exe")
    doLast {
    	// some code signing stuff

I thought I could wire setup.exe as an artifact. Here’s how I declared it:

artifacts {
	archives buildWindowsInstaller

But when I try to run this:

* What went wrong:
A problem occurred evaluating project ''.
> Cannot convert the provided notation to an object of type PublishArtifact: task ''.
  The following types/formats are supported:
    - Instances of PublishArtifact.
    - Instances of AbstractArchiveTask, for example jar..
    - Maps
    - Instances of File.

I thought target was the output, and was an instance of file?

I can use the output from buildWindowsInstaller' as the input to a Copy task in the from attribute.

(Mark Vieira) #2

You will have to explicitly tell Gradle the file to use here. Unfortunately you can only pass a Task instance when that task extends from AbstractArchiveTask. You could simply change your build script like so. This will also instruct Gradle that to publish this artifact it must execute the buildWindowsInstaller task.

artifacts {
    archives( {
        builtBy buildWindowsInstaller

Where are task inputs and outputs defined in the Gradle reference docs?
(Dan Gravell) #3

Thanks Mark, this gets it compiling.