談一談 Gradle 的倉庫(Repositories)

    首先,Repository 是什麼?Repository 是 文件的集合,這些文件,經過group、name和version 組織起來。在使用上,主要體現爲jar 和 xml文件maven

    Gradle 經過這些Repository 找到外部依賴(external dependencies.)gradle

    Gradle 並不默認指定任何倉庫。它支持不少中倉庫,如maven、ivy,經過文件訪問或者經過HTTP 訪問。下面舉例說明:ui

1.使用本地maven 倉庫:url

repositories {
  mavenLocal()()
}

2.使用遠程maven 倉庫:code

repositories {
    maven {
        url "http://repo.mycompany.com/maven2"
    }
}

3.使用本地的ivy 倉庫:
xml

repositories {
    ivy {
        // URL can refer to a local directory
        url "../local-repo"
    }
}

4.使用遠程的ivy 倉庫:ci

repositories {
   ivy {
        url "http://repo.mycompany.com/repo"
    }
}


一個工程可使用多個倉庫。那麼問題來了,怎麼尋找dependency呢?it

Gradle是這麼作的:io

    按照你在文件中(build.gradle)倉庫的順序尋找所需依賴(如jar文件),若是在某個倉庫中找到了,那麼將再也不其它倉庫中尋找。class

相關文章
相關標籤/搜索