如何确保 Aether 'downloads' 本地存储库中的所有依赖项?
How to make sure Aether 'downloads' all dependencies in your local repo?
我正在尝试解决项目的直接依赖关系,基本上是 运行 时间和编译时 POM 中的依赖关系以及传递。为此,我有以下代码
public class GetDirectDependencies
{
public static void main( String[] args )
throws Exception
{
System.out.println( "------------------------------------------------------------" );
System.out.println( GetDirectDependencies.class.getSimpleName() );
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession( system );
Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-impl:1.0.0.v20140518" );
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
descriptorRequest.setArtifact( artifact );
descriptorRequest.setRepositories( Booter.newRepositories( system, session ) );
ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor( session, descriptorRequest );
for ( Dependency dependency : descriptorResult.getDependencies() )
{
System.out.println( dependency );
}
}
}
这工作正常,但我如何获得 'resolved ' 依赖项列表。我需要能够在我的本地存储库中下载这个已解决的工件。基本上我需要一个 return 的列表,从中我可以找到本地磁盘上的 jar。
如果您需要 jar 文件和该 jar 的物理路径,您应该 'resolve' 它。我是通过以下方式实现的:
Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-util:1.0.0.v20140518" );
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact( artifact );
artifactRequest.setRepositories( Booter.newRepositories( system, session ) );
ArtifactResult artifactResult = system.resolveArtifact( session, artifactRequest );
artifact = artifactResult.getArtifact();
To get the file:
artifact.getFile();
我正在尝试解决项目的直接依赖关系,基本上是 运行 时间和编译时 POM 中的依赖关系以及传递。为此,我有以下代码
public class GetDirectDependencies
{
public static void main( String[] args )
throws Exception
{
System.out.println( "------------------------------------------------------------" );
System.out.println( GetDirectDependencies.class.getSimpleName() );
RepositorySystem system = Booter.newRepositorySystem();
RepositorySystemSession session = Booter.newRepositorySystemSession( system );
Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-impl:1.0.0.v20140518" );
ArtifactDescriptorRequest descriptorRequest = new ArtifactDescriptorRequest();
descriptorRequest.setArtifact( artifact );
descriptorRequest.setRepositories( Booter.newRepositories( system, session ) );
ArtifactDescriptorResult descriptorResult = system.readArtifactDescriptor( session, descriptorRequest );
for ( Dependency dependency : descriptorResult.getDependencies() )
{
System.out.println( dependency );
}
}
}
这工作正常,但我如何获得 'resolved ' 依赖项列表。我需要能够在我的本地存储库中下载这个已解决的工件。基本上我需要一个 return 的列表,从中我可以找到本地磁盘上的 jar。
如果您需要 jar 文件和该 jar 的物理路径,您应该 'resolve' 它。我是通过以下方式实现的:
Artifact artifact = new DefaultArtifact( "org.eclipse.aether:aether-util:1.0.0.v20140518" );
ArtifactRequest artifactRequest = new ArtifactRequest();
artifactRequest.setArtifact( artifact );
artifactRequest.setRepositories( Booter.newRepositories( system, session ) );
ArtifactResult artifactResult = system.resolveArtifact( session, artifactRequest );
artifact = artifactResult.getArtifact();
To get the file:
artifact.getFile();