Search code examples
mavenjcenter

How to force Maven to use jcenter repoistory


I was trying to get dependencies with mvn, but the problem is that one of packages is not in the officail repo. I've mananged to add jcenter to the sources, but maven seems not olwes to take look there.

Here it is looking correctly to the next repo

Downloading from central: https://repo.maven.apache.org/maven2/io/ktor/ktor-client-core/1.2.5/ktor-client-core-1.2.5.pom
Downloading from central: https://jcenter.bintray.com/io/ktor/ktor-client-core/1.2.5/ktor-client-core-1.2.5.pom

but here dont:

Downloading from central: https://repo.maven.apache.org/maven2/io/ktor/ktor-http/1.2.5/ktor-http-1.2.5.pom
[WARNING] Missing POM for io.ktor:ktor-http:jar:1.2.5

mvn -Dartifact=io.ktor:ktor-client-core:1.2.5 -DremoteRepositories=central::default::https://jcenter.bintray.com/ dependency:get


Solution

  • The io.ktor artifacts are currently not available at Maven Central for versions newer than 1.2.4. Therefore they have to be downloaded from the Jcenter repository.

    ktor-http has a depencency ktor-utils. When calling the dependency plugin for ktor-http Maven tries to download also the ktor-utils artifact. Unfortunately, the parameter -DremoteRepositories= is only taken into account for the artifact ktor-http but not for the dependency ktor-utils. Maven tries to download ktor-utils from Maven central and fails.

    You could solve the problem by calling

    mvn -Dartifact=io.ktor:ktor-utils:1.2.5 -DremoteRepositories=central::default::https://jcenter.bintray.com/  dependency:get
    

    before downloading ktor-http. However, this approach requires a lot of manual download steps and I would not suggest it.

    A better solution would be to add the Jcenter repository directly to your pom:

    <project>
      [...]
      <repositories>
        <repository>
          <id>jcenter</id>
          <name>jcenter</name>
          <url>https://jcenter.bintray.com</url>
        </repository>
      </repositories>
      [...]
    </project>
    

    A third option would be to add the Jcenter repository to your settings.xml.