Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a custom repository to gradle build file?

Tags:

gradle

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.

like image 966
Serge Nikitin Avatar asked Nov 11 '16 08:11

Serge Nikitin


People also ask

How do I add a dependency in build gradle?

To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.

What is Mavencentral () in gradle?

Maven Central is a popular repository hosting open source libraries for consumption by Java projects. To declare the Maven Central repository for your build add this to your script: Example 1. Adding central Maven repository. build.gradle.


1 Answers

 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/

like image 166
Bartosz Bilicki Avatar answered Oct 05 '22 06:10

Bartosz Bilicki