When I use "apply from" and dinamic tasks creation there is a missing ArchivePublishArtifact


(Victor Martinez) #1

For somehow there is a missing artifact when I split up a build gradle script in two different scripts:

  • build.gradle

which contains the build logic

  • promote.gradle

which will be used as common phase for different projects. It will iterate through each generated artifact and promote it into another stage environment.

build.gradle

apply plugin: "java"
  apply plugin: "maven"
  apply from: 'promote.gradle'
    //// build process already skipped.....
    task zipKit(type: Zip, dependsOn: copySQLToKit) {
    from('build/tmp/kit').into('XXXX-' + version)
    outputs.upToDateWhen {false}
  }
    artifacts {
 archives zipKit
  }
    uploadArchives {
 repositories {
  mavenDeployer {
   repository(url: 'http://artifactory/ci')
   snapshotRepository(url: 'http://artifactory/ci/')
   }
 }
  }

promote.gradle

apply plugin: "maven"
  apply plugin: "java"
    def promoteCommand = ['echo']
  configurations.archives.allArtifacts.each { def targetName ->
     tasks.add(name: "promoteArtefact$targetName", type: Exec) {
         commandLine promoteCommand + ['test', project.group, targetName.name, project.version]
     }
   }
     task promote(dependsOn: tasks.matching { Task task -> task.name.startsWith("promoteArtefact")})
     task mappings << {
    configurations.archives.allArtifacts.each { dep ->
        println " ${dep.getFile()}"
    }
  }

Current console output (just removed some tasks as part of the console output in order to make it more readable)

>gradlew tasks --all --daemon
:tasks
....
....
  Other tasks
-----------
promote [jar]
    promoteArtefactArchivePublishArtifact XXXX:jar:jar
start [classes, testClasses]

Current console output for mappings task

>gradlew --daemon mappings
:mappings
  D:\Workspaces\XXXX\build\libs\XXXX-0.0.0-dev.jar
  D:\Workspaces\XXXX\build\distributions\XXXX-0.0.0-dev.zip
  BUILD SUCCESSFUL

Console ouput for promote task

>gradlew --daemon promote
:promoteArtefactArchivePublishArtifact XXXX:jar:jar:
test com.platform XXXX 0.0.0-dev
:promote
  BUILD SUCCESSFUL

My question is, how can I get a complete list of all artifacts which they will be generated during a build and use that as part of another gradle script (apply from:)

Thanks