Changed behaviour in maven-publish between 5.5 and 5.6

I’m building an ejb library that produces a .jar file that should be published to a maven repository with a pomfile that specify packaging=ejb
When upgrading from gradle version 5.5.1 to 5.6 the artifact extension is changed during publication.
Test code:

plugins {
    id "java"
    id "maven-publish"
group = "mygroup"
version = "1.0.0"

publishing {
  publications {
    mavenJava(MavenPublication) {
      pom.packaging = "ejb"

When building with 5.5.1 the resulting files are:

When building with 5.6, the resulting files are:

In both cases the generated pomfile is correct with <packaging>ejb</packaging>

Is it the expected behaviour (the publication is changing the extension) or is it a bug?
If it is the expected behaivour, how do I preserve the “.jar”-extension?


I’m not sure if this is expected behavior or not… but you could likely fix it by

tasks.withType(Jar) {
   archiveExtension = 'jar' 

Thanks for the answer. Unfortunately that does not work with gradle 5.6+. It seems that the publication takes precedence over the archiveExtension. The extension is correct in $buildDir/libs, but when the publishing task (publish or publishToMavenLocal) is executed, the extension is changed on the published artifact.

Perhaps this documentation can help.


    it.extension == "ejb"
    it.extension = "jar"

Unfortunately that did not work either. The “artifact object” has the correct file and desired extension, but when setting the publication.package = “ejb” the uploaded extension is changed. :frowning:

The only solution I’ve have now is to modify the pom with “withXml”. But it feels like a hack.

Thanks for reporting this @hazze. This clearly is a regression. I opened:

It is caused by these changes which re-implemented part of the publishing process. There clearly was some test coverage for this missing. :frowning:

I am afraid the “withXml” workaround is the only thing you can do at the moment.