Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maven-publish publishes jars with wrong extension for known jar packagings like 'ejb' in 5.6 #10555

Closed
jjohannes opened this issue Sep 11, 2019 · 6 comments
Assignees
Milestone

Comments

@jjohannes
Copy link
Contributor

jjohannes commented Sep 11, 2019

Original report: https://discuss.gradle.org/t/changed-behaviour-in-maven-publish-between-5-5-and-5-6

⚠️ Workaround (for 5.6, 5.6.1, 5.6.2)

replace pom.packaging = "ejb"
with pom.withXml { asNode().appendNode("packaging", "ejb") }

Reproducing Example

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.2, 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
@jjohannes
Copy link
Contributor Author

This is caused by the reimplementation of part of the publishing in #9445 and the absence of test coverage for this special casing of handling the 'packaging' attribute.

@jjohannes jjohannes self-assigned this Sep 11, 2019
@jjohannes
Copy link
Contributor Author

In Gradle 6 we will no longer automatically change the file extension of an artifact based on the pom packaging - see #10607. That change also fixes this issue.

In case we consider another patch release for the 5.x release line, the following commit can be picked to restore the 5.5 behavior: a426d6e

@big-guy
Copy link
Member

big-guy commented Sep 11, 2019

@jjohannes To make sure I understand clearly...

older than 5.6, we publish a jar but the POM would say packaging is ejb.
with 5.6, we publish a ejb and the POM would say ejb.
with 6.0, we publish a jar and the POM would say ejb.

From the commit above, it seems like there will be more changes in 6.0 to address non-jar publications?

Ignoring what we used to do, which is more correct/intended by Maven? Should the packaging from the POM always match the extension of the published artifact or does it not really matter?

@larsgrefer
Copy link
Contributor

Adding my two cents here:

I'm the maintainer of a gradle-plugin which allows building maven-plugins with gradle and I just ran into the same problem. A maven-plugin has to publish a .jar file while the pom <packaging> has to be maven-plugin.

I therefore use something like this:

publishing {
  publications {
    mavenJava(MavenPublication) {
      from components.java
      pom.packaging = "maven-plugin"
    }
  }
}

This worked fine up until Gradle 5.5.1, but is broken with 5.6, 5.6.1 and 5.6.2

Therefore I'd answer this:

Should the packaging from the POM always match the extension of the published artifact or does it not really matter?

No, a mismatch between the pom <packaging> and the actual file extension is common practice in maven and should be supported by Gradle.

@jjohannes
Copy link
Contributor Author

@big-guy you understood correctly.

@larsgrefer thanks for clarifying. It's correct what you wrote. There is just one gotcha, which eventually let to this regression.

If you use a "non-known" extension as packaging, Maven (and Gradle) also look for an artifact where the packaging is the extension. I believe that is a mechanism to allow discovery of "non-jar" artifacts as there is no other way in the POM format to define those.

So if you use something like classifier=foo, Maven (and Gradle) would find the .foo artifact. What is known or not known is hard coded in Gradle (and Maven I believe) - "jar", "ejb", "bundle", "maven-plugin" (known to refer to a jar).

The regression in 5.6 is that this list is not honored in our reimplementation of publishing. So for any packaging, the extension is now changed.

The general problem is that changing the extension late in the publishing process breaks other things in Gradle. That's why for 6.0 we want to get rid of this "magic" completely in the publishing plugin.

So in 6.0, if you set packaing=foo (not in the known list), you will still publish a jar by default. But you can always change the artifact when it is produced to get the same result as before. I.e., configure the jar task like jar.archiveExtension.set('foo').

@jjohannes jjohannes reopened this Sep 13, 2019
larsgrefer added a commit to freefair/gradle-plugins that referenced this issue Oct 3, 2019
jjohannes added a commit that referenced this issue Oct 11, 2019
This restores the behavior before #9445 (before 5.6) and with
that fixes #10555.

The behavior for non-jar packaging is still problematic and should
be changed for 6.0 as it leads to broken Gradle Module Metadata.
@jjohannes jjohannes added this to the 5.6.3 milestone Oct 11, 2019
ljacomet pushed a commit that referenced this issue Oct 14, 2019
This restores the behavior before #9445 (before 5.6) and with
that fixes #10555.

The behavior for non-jar packaging is still problematic and should
be changed for 6.0 as it leads to broken Gradle Module Metadata.
@ljacomet
Copy link
Member

Closing as this was merged to 5.6.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants