Best way to include application zip/tar archives in maven-publish artifacts

I have a project using the application and maven-publish plugins. I want to include the results of the distTar and distZip tasks as archives that get uploaded to the Maven repository.

I’ve tried adding separate publications for the zip and tar archives, but these end up generating a pom which overwrites the main java pom.

publishing {
    publications {
        mavenDefault(MavenPublication) {
            from components.java
            artifact(sourceJar) {
                classifier "sources"
            }
        }
        zip(MavenPublication) {
            artifact distZip
        }
        tar(MavenPublication) {
            artifact distTar
        }
    }
    repositories {
       ...
    }
}

I tried to disable the Pom File generation tasks that get created for each MavenPublication, but this doesn’t seem to be allowed.

model {
    tasks.generatePomFileForTarPublication.enabled=false
    tasks.generatePomFileForZipPublication.enabled=false
}
A problem occurred evaluating root project '...'.
> No such property: enabled for class: org.gradle.model.dsl.internal.NonTransformedModelDslBacking

It appears that I can add the distZip and distTar artifacts to the mavenDefault publication, but only if I give them unique classifiers, in which case I end up with unwanted classifiers in the file names (e.g. foo-1.0.0-zip.zip).

Is there any way to prevent the other publications from generating a pom, or to not add the classifier into the filename of the published artifact if using the same publication?

Thanks, Andrew

try:

publishing {
   publications {
      create( 'myModule', MavenPublication ) {
         artifact distZip
         groupId 'myGroup'
         artifactId 'myModule'
         version 'myVersion'
      }
   }
}

I tried the following based upon your suggestion, and I get the same result as before - the zip pom replaces the jar pom

publications {
        mavenDefault(MavenPublication) {
            from components.java
            artifact(sourceJar) {
                classifier "sources"
            }
        }
        create('zip', MavenPublication) {
            artifact distZip
            groupId project.group
            artifactId project.name
            version project.version
        }
        create('tar', MavenPublication) {
            artifact distTar
            groupId project.group
            artifactId project.name
            version project.version
        }
    }

When I ran the original configuration against our Nexus snapshot repository, I noticed that we ended up with 3 sets of snapshots - for the jar + sources, tar.gz and zip, each with their own pom. I would suspect that the end result when retrieving the dependencies will be the same as the local repo - the latest version of the pom will win, which happens to be the zip version.

At this point it looks like adding the unwanted classifier and doing everything in a single publication will be the best option.