Publish applicationDistribution to maven

RE: gradle 6.9.2

I’m taking advantage of the gradle ‘application’ plugin to create a distribution zip file that includes everything needed (except the JVM) to launch a Java application. I cannot figure out what magic is required to include the zip file as part of the maven publication. More specifically, I don’t know the right magic incantation to refer to the application output when creating a MavenArtifact. My publications block currently looks as follows

publications {
  mavenJava(MavenPublication) {
    version project.version


    artifact sourcesJar

    artifact source:application, extension:'zip' // <- doesn't work

I’ve tried several variations to try to refer to the application distribution, but none of them have worked. All of the errors are of the form "Cannot convert the provided notation to an object of type MavenArtifact: extension ‘application’. I’m scouring the source code to figure this out without any success so far. Any pointers to documentation that explain how to do this would be greatly appreciated!

I found that the following works, but is brittle hack, because I have to assume the location of the file inside of build/distributions and the format for the name of the zip file created by the application plugin, both of which could very easily change in the future.

artifact "${buildDir}/distributions/${applicationName}-${project.version}.zip"

Are you sure you want to put that archive in a Maven repository?
Usually this is not the best idea, as Maven repositories are meant for distributing single libraries and their dependencies and not to publish ready-made application ZIPs.

If you are really sure, you want that, don’t use the application extension that you use to configure the application plugin, but the Zip task generating the actual zip. So source:distZip is what you want to use.

Using hard-coded paths is not only bad because of the hard-coding, but also because you don’t have task implicit task dependencies then and so can easily publish a stale artifact.

And artifact sourcesJar should not be necessary. If you used withSourcesJar(), then it is part of the java component already.

Björn, Thank you very much. I do want to publish this zip file. It’s actually a protobuf plugin, and I need an execution script to be included that can be passed to protoc if another library wants to use my plugin. I haven’t found another way to do this.

I’m not familiar with protcol buffers and I maybe didn’t fully get the situation.
But maybe a feature variant would be a better way.
Especially as Gradle users then can use variant-aware resolution to get it.