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

remove-project-artifact doesn't remove metadata #64

Open
chrylis opened this issue Jul 11, 2018 · 2 comments
Open

remove-project-artifact doesn't remove metadata #64

chrylis opened this issue Jul 11, 2018 · 2 comments

Comments

@chrylis
Copy link

chrylis commented Jul 11, 2018

As a workaround for a rough spot in Artifactory, I'm using remove-project-artifact to clear artifacts from test builds on a Jenkins server. However, the metadata for the removed artifact isn't cleared, which means that the next time that Jenkins tries to build a project that depends on "this" one with a matching version range, the downstream build fails because Jenkins can't resolve the "missing" version. These projects are not resolved from any external repository when built on the CI server.

Reproduction:

  • create project A with version 0.1.0, install
  • update A to 0.1.1, install, run remove-project-artifact
  • create project B that depends on A:[0.1.0,0.2.0)

Expected behavior: B resolves the latest existing version of A (0.1.0). Instead, it resolves the removed version 0.1.1, and the Maven build fails.

Example maven-metadata-local.xml "before":

<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>io.ngin.sandbox.build</groupId>
  <artifactId>build-sandbox</artifactId>
  <versioning>
    <release>3.0.1</release>
    <versions>
      <version>3.0.0</version>
      <version>3.0.1</version>
    </versions>
    <lastUpdated>20180709210726</lastUpdated>
  </versioning>
</metadata>

Example after version 3.0.2 was installed and deleted (this will fail because 3.0.2 doesn't exist):

<?xml version="1.0" encoding="UTF-8"?>
<metadata>
  <groupId>io.ngin.sandbox.build</groupId>
  <artifactId>build-sandbox</artifactId>
  <versioning>
    <release>3.0.2</release>
    <versions>
      <version>3.0.0</version>
      <version>3.0.1</version>
      <version>3.0.2</version>
    </versions>
    <lastUpdated>20180711173248</lastUpdated>
  </versioning>
</metadata>
@lasselindqvist
Copy link

The right approach is probably as Maven core does it and read and write the changes the following way:

Reader reader = ReaderFactory.newXmlReader( metadataFile );
MetadataXpp3Reader mappingReader = new MetadataXpp3Reader();
Metadata metadata = mappingReader.read( reader, false );
metadata.getVersioning().removeVersion(project.getArtifact().getVersion());
Writer writer = WriterFactory.newXmlWriter( metadataFile );
MetadataXpp3Writer mappingWriter = new MetadataXpp3Writer();
mappingWriter.write( reader, false );

with proper catch clauses closing of the streams.

@slawekjaranowski
Copy link
Member

Simply we should not edit maven-metadata-local.xml it is internal Maven feature and may be changed in some version

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

No branches or pull requests

4 participants