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) {
      from components.java
      pom.packaging = "ejb"
    }
  }
}

When building with 5.5.1 the resulting files are:
~/.m2/repository/mygroup/ejbtest/1.0.0/ejbtest-1.0.0.jar
~/.m2/repository/mygroup/ejbtest/1.0.0/ejbtest-1.0.0.pom

When building with 5.6, the resulting files are:
~/.m2/repository/mygroup/ejbtest/1.0.0/ejbtest-1.0.0.ejb
~/.m2/repository/mygroup/ejbtest/1.0.0/ejbtest-1.0.0.pom

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?

/Hans

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.

Eg:

publication.artifacts.matching({
    it.extension == "ejb"
}).all({
    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: https://github.com/gradle/gradle/issues/10555

It is caused by these changes https://github.com/gradle/gradle/pull/9445 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.