从远程行家回购编程下载工件(Downloading artifacts from remote ma

2019-10-22 18:52发布

我使用以太工具库来管理deppendencies。 当我尝试下载传递依赖的Maven构件,我收到了

java.io.IOException: Invalid Content-Range header for partial download

错误。 我使用几乎相同的代码从这里以太例如https://github.com/eclipse/aether-demo/blob/master/aether-demo-snippets/src/main/java/org/eclipse/aether/examples/ ResolveTransitiveDependencies.java

  /**
  * Resolves the transitive (compile) dependencies of an artifact.
   */

公共类ResolveTransitiveDependencies {

public static void main( String[] args )
    throws Exception
{
    System.out.println( "------------------------------------------------------------" );
    System.out.println( ResolveTransitiveDependencies.class.getSimpleName() );

    RepositorySystem system = Booter.newRepositorySystem();

    RepositorySystemSession session = Booter.newRepositorySystemSession( system );

    Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-impl:1.0.0.v20140518" );

    DependencyFilter classpathFlter = DependencyFilterUtils.classpathFilter( JavaScopes.COMPILE );

    CollectRequest collectRequest = new CollectRequest();
    collectRequest.setRoot( new Dependency( artifact, JavaScopes.COMPILE ) );
    collectRequest.setRepositories( Booter.newRepositories( system, session ) );

    DependencyRequest dependencyRequest = new DependencyRequest( collectRequest, classpathFlter );

    List<ArtifactResult> artifactResults =
        system.resolveDependencies( session, dependencyRequest ).getArtifactResults();

    for ( ArtifactResult artifactResult : artifactResults )
    {
        System.out.println( artifactResult.getArtifact() + " resolved to " + artifactResult.getArtifact().getFile() );
    }
}

}

Answer 1:

我通过删除本地仓库神器瓶解决了这个问题,但我仍然不知道为什么这发生异常时,似乎当网络不稳定发生。 希望这将有助于。



文章来源: Downloading artifacts from remote maven repo programmatically