Exec command, wix, and artifactoryPublishing problem

I have a task that produces an MSI using wix and am having a hard time getting that aligned with an artifactory publish. I thought it was due to output declaration but I end up with this error.

A problem occurred evaluating script. > Cannot convert the provided notation to an object of type PublishArtifact: task ‘:wfm-reporting-msi:wfm-reporting-install-green:wixLight’.

The following types/formats are supported:

  • Instances of PublishArtifact.

  • Instances of AbstractArchiveTask, e.g. jar.

  • Maps

  • Instances of File.

The task is defined as follows and depends on one before it (also an exec):

task wixLight(dependsOn: wixCandle) {
 description 'Links and binds one or more .wixobj files and creates a Windows Installer database.'
 File out = file("${buildDir}/libs/${project.name}-${project.version}.msi")
   //destFile = file("${buildDir}/libs/*.msi")
 outputs.upToDateWhen { false }
    doLast {
  println "Exec Time: ${project.msiName}"
  if (project.hasProperty("msiName")) {
   out = file("${buildDir}/libs/${msiName}")
  }
                  outputs.file out
                  exec {
         executable file("${buildDir}\wix-lib\wix-" + wixVersion + "\bin\light.exe")
   args "-out", out
   args fileTree(wixCandle.outputs.files.singleFile).files
   args "-ext", "WixUtilExtension.dll"
   args "-ext", "WixUIExtension.dll"
  }
 }
}

with an artifact declaration of

artifacts {
    archives wixLight
}

As the error suggests, Gradle cannot infer the artifact output of your task. You’ll have to explicitly tell Gradle what to publish.

artifacts {

archives wixLight.outputs.files.singleFile

}

Tried that and it had an error, we ended up using the following but I’m not sure I fully understand why one works vs. the other - thanks for the suggestion though.

artifacts {
 File artifactDir = file("${buildDir}/libs/")
 if (artifactDir != null && artifactDir.listFiles() != null && artifactDir.listFiles().size() > 0) {
  archives artifactDir.listFiles().findAll { it.name.endsWith(".msi") }.first()
 }
}

I think it is because your task outputs are not available at configuration time. Try moving the following code outside of the ‘doLast {…}’ block.

if (project.hasProperty(“msiName”)) {

out = file("${buildDir}/libs/${msiName}")

}

outputs.file out