如何在Aether中添加RemoteRepository以获得直接依赖关系?

时间:2015-01-30 11:44:32

标签: java maven aether

我正在使用以下代码添加远程存储库以使用以太从工件中获取依赖关系。

    public static void main( String[] args )
            throws Exception
        {
            RepositorySystem system = Booter.newRepositorySystem();
            Artifact artifact = new DefaultArtifact( "org.apache.logging.log4j:log4j-api:2.1" );
            List<RemoteRepository> repositories = new ArrayList<RemoteRepository>();


        repositories.add((new RemoteRepository.Builder("central", "", "https://repo1.maven.org/maven2")).build());


        DefaultRepositorySystemSession session = Booter.newRepositorySystemSession(system);

        ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
        descriptorRequest.setArtifact( artifact );
        descriptorRequest.setRepositories( system.newResolutionRepositories(session, repositories ) );

        ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor( session, descriptorRequest );

        for ( Dependency dependency : descriptorResult.getDependencies() )
        {
            System.out.println( dependency );
        }
    }

但在尝试读取工件描述符时会提示以下错误消息。

Exception in thread "main" org.eclipse.aether.resolution.ArtifactDescriptorException: Failed to read artifact descriptor for org.apache.logging.log4j:log4j-api:jar:2.1
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:329)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.readArtifactDescriptor(DefaultArtifactDescriptorReader.java:217)
    at org.eclipse.aether.internal.impl.DefaultRepositorySystem.readArtifactDescriptor(DefaultRepositorySystem.java:287)
    at org.eclipse.aether.examples.GetDirectDependencies.main(GetDirectDependencies.java:48)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
Caused by: org.eclipse.aether.resolution.ArtifactResolutionException: Could not transfer artifact org.apache.logging.log4j:log4j-api:pom:2.1 from/to central (https://repo1.maven.org/maven2): Cannot access https://repo1.maven.org/maven2 with type  using the available connector factories: BasicRepositoryConnectorFactory
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:444)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifacts(DefaultArtifactResolver.java:246)
    at org.eclipse.aether.internal.impl.DefaultArtifactResolver.resolveArtifact(DefaultArtifactResolver.java:223)
    at org.apache.maven.repository.internal.DefaultArtifactDescriptorReader.loadPom(DefaultArtifactDescriptorReader.java:314)

0 个答案:

没有答案