Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-69848

Resolving of snapshot revisions doesn't work anymore due to missing JAXB in Java 11

XMLWordPrintable

      Resolving of snapshot revisions doesn't work anymore in the maven-metadata-plugin due to missing JAXB in Java 11.

      A JAXB fix was done in JENKINS-68510 with PR https://github.com/jenkinsci/maven-metadata-plugin/pull/22 and released in version 2.2. However, this doesn't fix the problem with resolving snapshot revisions.

      ssturm provided a possible fix for this in the comments of JENKINS-68510. That fix solves the issue. Can this fix be implemented?

      private String resolveSnapshotRevision(String version) {
        InputStream input = null;
        try {
          LOGGER.finest("Resolving SNAPSHOT version if any...");
          URL url = new URL(getArtifactUrlForPath(version+"/maven-metadata.xml"));
      
          LOGGER.finest("Requesting metadata from URL: "+url.toExternalForm());
      
          URLConnection conn = prepareConnection(url);
      
          input = conn.getInputStream();
      
          Thread currentThread = Thread.currentThread();
          ClassLoader originalContext = currentThread.getContextClassLoader();
          try {
            currentThread.setContextClassLoader(MavenMetadataParameterDefinition.class.getClassLoader());
            JAXBContext context = JAXBContext.newInstance(MavenMetadataVersions.class);
            Unmarshaller unmarshaller = context.createUnmarshaller();
            MavenMetadataVersions metadata = (MavenMetadataVersions) unmarshaller.unmarshal(input);
      
            if (metadata.versioning.snapshot != null && !StringUtils.isEmpty(metadata.versioning.snapshot.timestamp)) {
              return version.replaceAll("SNAPSHOT", "") +  metadata.versioning.snapshot.timestamp + "-" + metadata.versioning.snapshot.buildNumber;
            }
          } finally {
            currentThread.setContextClassLoader(originalContext);
          }
      
        } catch (Exception e) {
          LOGGER.log(Level.WARNING, "Could not parse maven-metadata.xml", e);
        } finally {
          try {
            if (input != null)
              input.close();
          } catch (IOException e) {
            // ignore
          }
        }
        // we did not find anything, return the original value
        LOGGER.finest("No match found, using default");
        return version;
      }  

            marcrohlfs Marc Rohlfs
            poldenburg Paul Oldenburg
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: