Class AetherUtilities


  • public class AetherUtilities
    extends Object
    Taken and adapted from: https://stackoverflow.com/questions/48537735/download-artifact-from-maven-repository-in-java-program
    • Method Detail

      • getRemoteArtifactMetadata

        public static List<org.eclipse.aether.resolution.MetadataResult> getRemoteArtifactMetadata​(MavenArtifact a)
                                                                                            throws MavenException

        Returns the results of metadata requests regarding the request coordinates represented by the passed MavenArtifact.

        Note that the passed artifact really only represents the expected location of the metadata to retrieve. Releases do not have metadata; snapshots have metadata and only the latest one will be returned. To get the meta data about the artifact regardless of its version, leave the version and packaging fields of the given MavenArtifact empty.

        Parameters:
        a -
        Returns:
        Throws:
        MavenException
      • getDependencies

        public static Stream<org.eclipse.aether.artifact.Artifact> getDependencies​(MavenArtifact requestedArtifact)
                                                                            throws MavenException
        Retrieves the dependency tree that has requestedArtifact as its root. Thus, the requestedArtifact is resolved itself and included in the returned artifacts.
        Parameters:
        requestedArtifact - The Maven artifact to retrieve dependencies for.
        Returns:
        The resolved dependencies of requestedArtifact, including requestedArtifact itself.
        Throws:
        MavenException - If an artifact cannot be found or another Maven related error occurs.
      • getVersions

        public static Stream<String> getVersions​(MavenArtifact requestedArtifact,
                                                 String lowerBound,
                                                 String upperBound,
                                                 boolean lowerInclusive,
                                                 boolean upperInclusive)
                                          throws MavenException
        Retrieves all versions of the given artifact - whose given version is ignored in this method - that are available within the described version range.
        Parameters:
        requestedArtifact -
        lowerBound -
        upperBound -
        lowerInclusive -
        upperInclusive -
        Returns:
        Throws:
        MavenException
      • getNewestVersion

        public static String getNewestVersion​(MavenArtifact requestedArtifact)
                                       throws MavenException
        Retrieves all available versions of the given artifact and returns the newest one or null, if no version is available.
        Parameters:
        requestedArtifact -
        Returns:
        Throws:
        MavenException
      • getDependencies

        public static Stream<org.eclipse.aether.artifact.Artifact> getDependencies​(MavenArtifact requestedArtifact,
                                                                                   boolean recursiveCall)
                                                                            throws MavenException
        Retrieves the dependency tree that has requestedArtifact as its root. Thus, the requestedArtifact is resolved itself and included in the returned artifacts.
        Parameters:
        requestedArtifact - The Maven artifact to retrieve dependencies for.
        Returns:
        The resolved dependencies of requestedArtifact, including requestedArtifact itself.
        Throws:
        MavenException - If an artifact cannot be found or another Maven related error occurs.