D
D
Dmitry Roo2015-08-13 16:38:47
gradle
Dmitry Roo, 2015-08-13 16:38:47

How to build a project in Gradle when there is no internet?

There is someone else's project on Gradle. The problem is that when building, gradle tries to download dependencies from the Internet, and for some reason it fails (probably connection problems). How to build a project by downloading components manually? Where to put them?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Yarosh, 2015-08-14
@xez

You need to check the definition of existing Maven / Ivy repositories in the build.gradle of the desired module.
And here's what you can do there:

repositories {
    ivy {
        url "http://mycompany.com/repo" // нужно проверить доступность
        // или
        url "../local-ivy-repo" // для локальной папки с Ivy репозиторием
        
        // В Ivy можно указать структуру каталогов для поиска и путь к ivy.xml явно
        // Таким образом можно описать путь для любых зависимостей по http/https'у 
        layout 'pattern' , { 
            artifact '[module]/[revision]/[artifact](.[ext])'
            ivy '[module]/[revision]/ivy.xml'
        }
    }

    // Тоже самое можно и для Maven'a
    maven {
        url "http://repo.mycompany.com/maven2"
        // или
        url "../local-maven-repo"

        // В MavenArtifactRepository нет возможности прописать Layout, по понятным причинам

        // А ещё и в Ivy и в Maven'e можно указать пароль к AWS'у или http auth, правда это нестабильная фича
        credentials { // или credentials(AwsCredentials) {
            accessKey "myAccessKey"
            secretKey "mySecret"
        }
    }
}

Maven and Ivy use different folder structures, so be aware of this when making changes manually. Although for Ivy you can explicitly specify the layout 'pattern' for a self-made structure, but in Maven'e afaik this is not possible.
If you don’t bother at all, you can put all the jars in the libs folder and add them as dependencies, like this
dependencies {
    runtime files('libs/a.jar', 'libs/b.jar')
    // ну, или так
    runtime fileTree(dir: 'libs', include: '*.jar')
}

Write if you need to clarify something.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question