How to add a custom repository to gradle build fil

2019-04-06 17:44发布

问题:

I want to switch from maven to gradle.

In the pom.xml file I have a custom repository:

    <repositories>
    <repository>
        <id>my_rep_name</id>
        <url>http://*********</url>
    </repository>
</repositories>

It's a simple http web server with .jar files.

How can I add this custom repo to the build.gradle?

I tried this code, but it does not work:

repositories {
    mavenCentral()
    maven {
        url 'http://******'
    }
}

My custom repo is not a maven repo, but I did not find another examples in the Gradle documentation where I can specify the URL.

回答1:

 maven {
        url 'https://repo url'
        credentials {
            username = "username"
            password = "password"
        }
    }

Is definetly the way to go (for maven repository). What version of gradle are you using? What error message do you get? Maybe artefact you are trying to resolve is not to be found in that custom repository?

Gradle supports following formats: https://docs.gradle.org/current/userguide/dependency_management.html#sec:repositories

  • maven
  • ivy
  • flat directory

For external repository that is neither Maven nor Ivy, I think you have to fallback to flat directory. You have to copy required jars to your own project and use it as flat directory repository.

Flat directory repository may also be used as 'poor's man replacement' for proper maven repository. You may create directory structure, put files (your dependencies) there, then checkout this directory. Then other project would use dependencies from this directory.

When you have many custom artifacts that are shared among many projects people usually setup their own maven repository (Maven-format) and use it for such custom dependencies. To setup your own repository you may use https://www.jfrog.com/open-source/



标签: gradle