Is it possible to bind publish procedure output fi...
# community-support
u
Is it possible to bind publish procedure output files to the task output? I need to a task
zipBundle
to publish/upload a java library to MavenCental which is bunch of jar files including hash and signatures. The publish extension configured to prepared staging artifacts in local directory
Copy code
repositories {
    maven {
        name = "localStaging"
        // change URLs to point to your repos, e.g. <http://my.org/repo>
        val releasesRepoUrl = uri(layout.buildDirectory.dir("repos/releases"))
        val snapshotsRepoUrl = uri(layout.buildDirectory.dir("repos/snapshots"))
        url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
    }
}
The publish extension dynamically generates several tasks, and one of them
publishMavenJavaPublicationToLocalStagingRepository,
generates all artifacts. This tasks properly create necessary directory structure fit the MavenCentral requirements. I left only to create a zip bundle which is very simple.
Copy code
val zipBundle by tasks.registering(Zip::class) {
    archiveFileName = "central-bundle.zip"
    destinationDirectory = project.layout.buildDirectory.dir("distributions")
    from(project.layout.buildDirectory.dir("repos/releases"))
}
But this has not direct binding between
zipBundle
tasks and
publishMavenJavaPublicationToLocalStagingRepository
. I did succeed to bind task
zipBundle
to
uploadToMavenCentral.
If i trigger
uploadToMavenCentral
it will trigger
zipBundle
as the output of
zipBundle
is the input for
uploadToMavenCentral
Now I need to do the same between
publishMavenJavaPublicationToLocalStagingRepository and zipBundle
This snippet
Copy code
val dummy by tasks.registering {
    var pb = tasks.getByName("publishMavenJavaPublicationToLocalStagingRepository")
    println(pb.outputs.files.files)
}
show than generated publish tasks doens't declare the generated artifacts as an output of task. Is there way to overcome it?
v
Whether that task should have this directory as output when the configured repository is a local directory based one is probably debatable. I'd recommend opening a bug or feature request ticket for that. In the meantime you can just use
outputs.dir
to add the directory as output of the task to achieve the intended wiring.
u
@Vampire In the meantime you can just use
outputs.dir
to add the directory as output of the task to achieve the intended wiring.
It did the trick, this part if not obvious in Javdoc how to declare outputs.dir but after playing couple of hours I archived it. Worth smooth.