Skip to content

Add support for publishing maven-metadata.xml #1260

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

fzakaria
Copy link

@fzakaria fzakaria commented Oct 3, 2024

Maven repositories normally have a maven-metadata.xml file that indicate to the Maven system what versions are available and which is to be considered the latest version.

<metadata modelVersion="1.1.0">
    <groupId>com.mycompany.app</groupId>
    <artifactId>my-app</artifactId>
    <versioning>
        <latest>1.0</latest>
        <release>1.0</release>
        <versions>
            <version>1.0</version>
        </versions>
        <lastUpdated>20200731090423</lastUpdated>
    </versioning>
</metadata>

At Confluent, we use AWS Code Artifactory which does not mark a Maven package as "published" unless a new maven-metadata.xml is uploaded indicating so.

  • Add support for reading existing maven-metadata.xml
  • Add support for adding the new version to the metadata object
  • Add support to upload the file for http & file protocols
  • Add small test cases to validate SerDe for Maven metadata object from XML

Co-authored-by: Vince Rose vrose@confluent.io
Co-authored-by: Na Lou nlou@confluent.io

@fzakaria
Copy link
Author

fzakaria commented Oct 3, 2024

@shs96c we added a flag to keep it backwards compatible, but we are of the opinion the default should be true.
Let us know what you think.

Copy link
Author

@fzakaria fzakaria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We tested this locally using:

bazel run //tests/integration/pom_file:pom-example-with-runtime-dep.publish --define "maven_repo=file:///tmp/.m2"

(Note: we had to have set the publish_maven_metadata attr for the target)

Internally at Confluent, we tested the publishing via HTTP to AWS Code Artifactory as well.

ByteArrayOutputStream os = new ByteArrayOutputStream();
new MetadataXpp3Writer().write(os, metadata);
Files.write(newMavenMetadataXml, os.toByteArray());
return upload(mavenMetadataUrl, credentials, newMavenMetadataXml);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: upload could probably take InputStream but I didn't want to change too much of the code;
Open to doing another pass after on this file if you are open to it.

* Attempts to download the file at the given targetUrl.
* Valid protocols are: http(s) & file at the moment.
*/
private static CompletableFuture<Optional<String>> download(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could move this to a separate file Downloaders to keep this file a bit smaller.

@shs96c
Copy link
Collaborator

shs96c commented Dec 2, 2024

The test failures look genuine.

I think the upload of the metadata should be disabled by default. Both Nexus and Artifactory can automatically calculate the maven metadata for you, and it's not always clear that every publish should result in the metadata being updated (eg. if you push an release candidate of a given library you may not want all users to update from the stable release)

fzakaria and others added 3 commits March 6, 2025 15:47
Maven repositories normally have a maven-metadata.xml file that indicate to the Maven
system what versions are available and which is to be considered the latest version.

```xml
<metadata modelVersion="1.1.0">
    <groupId>com.mycompany.app</groupId>
    <artifactId>my-app</artifactId>
    <versioning>
        <latest>1.0</latest>
        <release>1.0</release>
        <versions>
            <version>1.0</version>
        </versions>
        <lastUpdated>20200731090423</lastUpdated>
    </versioning>
</metadata>
```

At Confluent, we use AWS Code Artifactory which does not mark a Maven package as "published" unless
a new maven-metadata.xml is uploaded indicating so.

* Add support for reading existing maven-metadata.xml
* Add support for adding the new version to the metadata object
* Add support to upload the file for http & file protocols
* Add small test cases to validate SerDe for Maven metadata object from XML

Co-authored-by: Vince Rose <vrose@confluent.io>
Co-authored-by: Na Lou <nlou@confluent.io>
* Add s3 handling for maven-metadata

Co-authored-by: jainruchir <rujain@confluent.io>

* code review

---------

Co-authored-by: jainruchir <rujain@confluent.io>
@vinnybod vinnybod force-pushed the upload-maven-metadata branch from d982843 to 81012bc Compare March 7, 2025 16:23
@vinnybod
Copy link
Contributor

vinnybod commented Mar 7, 2025

This also adds support for publishing to S3 which requires the client to update the maven-metadata.xml 🙂

@shs96c I addressed the broken test and it is disabled by default.

Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though I'm worried about the new http client we've pulled in.

return CompletableFuture.supplyAsync(
() -> {
try {
HttpTransport httpTransport = new NetHttpTransport();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All versions of the JDK that we support have the native HTTP handler. We already use this in the HttpDownloader class, which also handles things like using the .netrc file if there is one. Perhaps use that? We could do that in a follow-up PR, but what I don't want to happen is for us to have a proliferation of http clients in this repo.

@@ -0,0 +1,74 @@
package com.github.bazelbuild.rules_jvm_external.maven;

import static org.junit.Assert.*;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you need to run bazel run scripts:format

@shs96c
Copy link
Collaborator

shs96c commented Mar 19, 2025

Could you please run bazel run scripts:format, or otherwise expand the wildcard imports?

@vinnybod
Copy link
Contributor

I removed the extra http client dependency. Tests are passing, but I need to do a bit more end to end testing since I just merged ~4 months of commits from master.

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

Successfully merging this pull request may close these issues.

3 participants