Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
186 views
in Technique[技术] by (71.8m points)

java - How to resolve OSGi bundle artifacts using Eclipse aether

My maven plugin uses the following code to find the latest version of the current artifact and to resolve it:

try {
    VersionRangeResult versionRangeResult = mavenParameters.getRepoSystem()
        .resolveVersionRange(mavenParameters.getRepoSession(), versionRangeRequest);
    List<org.eclipse.aether.version.Version> versions = versionRangeResult.getVersions();
    filterSnapshots(versions);
    filterVersionPattern(versions, pluginParameters);
    if (!versions.isEmpty()) {
        String packaging = mavenProject.getPackaging();
        DefaultArtifact artifactVersion = new DefaultArtifact(mavenProject.getGroupId(), mavenProject.getArtifactId(), packaging,
            versions.get(versions.size()-1).toString());
        ArtifactRequest artifactRequest = new ArtifactRequest(artifactVersion, mavenParameters.getRemoteRepos(), null);
        ArtifactResult artifactResult = mavenParameters.getRepoSystem().resolveArtifact(mavenParameters.getRepoSession(), artifactRequest);
        if (artifactResult.isMissing() || (artifactResult.getExceptions() != null && !artifactResult.getExceptions().isEmpty())){
            throw new MojoFailureException("Could not resolve artifact: " + artifactVersion);
        }
        return artifactResult.getArtifact();
    } else {
        throw new MojoFailureException("Could not find previous version for artifact: " + artifactVersionRange.getGroupId() + ":"
            + artifactVersionRange.getArtifactId());
    }
} catch (final VersionRangeResolutionException | ArtifactResolutionException e) {
    getLog().error("Failed to retrieve comparison artifact: " + e.getMessage(), e);
    throw new MojoFailureException(e.getMessage(), e);
}

The code above works fine for "normal" artifacts like "jar" or "war" files, but it fails with an ArtifactResolutionException if the artifact has the packaging bundle:

    <artifactId>test-maven-plugin-packaging-bundle</artifactId>
    <packaging>bundle</packaging>

How can I resolve custom packagings like bundle?

question from:https://stackoverflow.com/questions/65860581/how-to-resolve-osgi-bundle-artifacts-using-eclipse-aether

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...