How to get a complete list of all artifacts generated by a build

By project generates a tgz and a war file (it is also generating a jar file for some reason, but that is another issue)

I’m currently using:

configurations.archives.allArtifacts

which returns only the tgz generated by the build.

I’ve examined other configurations as well. For example, configurations.default and configurations.runtime both give me the jar file generated by my build but not the war. This is confusing because I’m not really sure why the jar file is being generated in the first place. According to the docs for the War plugin, jar archive generation is disabled by the War plugin.

My question is, how can I get a complete list of all artifacts generated during a build?

It seems that adding my custom Tar task obscures or removes the war artifact under the archives configuration. In other words, if I remove the Tar task from my build,

println "Archives Artifacts: " + configurations.archives.allArtifacts

gives:

Archives Artifacts: [ArchivePublishArtifact_Decorated test:war:war:]

Adding my Tar task back and assigning its artifacts to a custom configuration with:

artifacts {
    tarDist tasks.tarDist
  }

The same println statement from above gives

Archives Artifacts: [ArchivePublishArtifact_Decorated test:tgz:tgz:]

I’ve found a workaround for the issue.

My custom tar task mentioned above is created from an external .gradle file and applied to a given project so that it can be used across our projects.

apply from: "${buildTools}/plugins/tarDist.gradle"

The tarDist.gradle file creates a tar task and created a configuration named “dist”.

If consumers of the tarDist.gradle applies the war plugin first and the tarDist.gradle second, no problems occur and there are two artifacts in configurations.archives.allArtifacts.

If the order is reversed and the tarDist.gradle is applied before the war plugin, then configurations.archives.allArtifacts contains only the tgz generated from the tarDist.gradle file.

The tarDist.gradle file:

configurations {
  dist
}
  task tarDist (type: Tar) {
  visible = true
  // ensure this task always runs
  outputs.upToDateWhen { false }
    compression=Compression.GZIP
  // include everything under src/dist
  from ("${project.projectDir}/src/dist/") {
    include ("**/*")
    into( "" )
  }
    // include everything under build/dist/* if it exists
  from ("${project.buildDir}/dist/"){
    include ("**/*")
    into( "" )
  }
    //make sure files under the bin dir are executable
  eachFile { fileCopyDetails ->
    logger.debug("Archiving file: ${fileCopyDetails.path}")
    if( fileCopyDetails.name.matches(".*[.](sh|bat|exe)") )
      fileMode = 0755
    else if( fileCopyDetails.path.matches("^scripts/.*") )
      fileMode = 0755
    else
      fileMode = 0644
  }
}
  artifacts {
  dist tarDist
 }

And a sample file that might use the tarDist.gradle

apply plugin: 'war'
apply from: "gradle/plugins/tarDist.gradle"
version="1.0"
  task printInfo << {
  println "Archives: ${configurations.archives.allArtifacts}"
}

Simply changing the order of the two apply statements will cause the behavior described above where the war file doesn’t show up in the configurations.archives.allArtifacts set.