Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository parameter of ArtifactResolver's constructor does not work #20

Open
ufolr opened this issue Oct 3, 2020 · 2 comments
Open

Comments

@ufolr
Copy link

ufolr commented Oct 3, 2020

When create ArtifactResolver with custom local repository or custom remote repository mirror, it can't resolve the pom.

This issues can replay with below code:

@Test
public void testResolvePomWithCustomLocalRepo(){
    String localRepo = "D:/Maven/.m2/repo";
    String mavenCenterMirror = "http://mirrors.cloud.tencent.com/nexus/repository/maven-public/";
    ArtifactResolver artifactResolver = new ArtifactResolver(localRepo, mavenCenterMirror);
    File pomFile = new File("src/test/poms/maven-core-3.0.4.pom");
    Assert.assertTrue(pomFile.canRead());
    List<Artifact> artifacts = artifactResolver.resolvePom(pomFile);

    Assert.assertNotNull(artifacts, "artifacts is null");
    for (Artifact artifact : artifacts) {
        Assert.assertNotNull(artifact.getFile(), "Artifact " + artifact + " is not resolved");
    }
}
@ufolr
Copy link
Author

ufolr commented Oct 3, 2020

Many times, we may custom local maven repo to other location except “~/.m2/repository”.
And also when we can't connect the official maven repo directly or it's very slow to downloading from official repo, such as in a internal network, we need custom the remote repo as a mirror and expect downloading for the mirror.

@ufolr ufolr changed the title Custom repository does not work. Repository parameter of class ArtifactResolver's constructor does not work Oct 9, 2020
@ufolr ufolr changed the title Repository parameter of class ArtifactResolver's constructor does not work Repository parameter of ArtifactResolver's constructor does not work Oct 9, 2020
@ufolr
Copy link
Author

ufolr commented Oct 9, 2020

I find this is because, in function MavenProject getMavenProject(File pomFile), it always use the default repository

request.setLocalRepository(lrs.createDefaultLocalRepository());
request.setRemoteRepositories(Arrays.asList(new ArtifactRepository[] {lrs.createDefaultRemoteRepository()}.clone()));

The repository set on constructor does not use when request the pom and jar file.

so I make a PR #21 to set the repository to request, it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant