1. 程式人生 > >IDEA引入Gradle工程小記

IDEA引入Gradle工程小記

ref mage tails -s cached pan 基本上 ans htm

1.首先IDEA要在該工程Settings中配置本地安裝的Gradle,配好其home目錄,註意目錄到根目錄即可,不要到bin一級,否則提示錯誤,無法使用:

技術分享圖片

2.配置好後會自動偵測Gradle項目,點擊右下角自動引入依賴

3.有些依賴無法下載,右上角有提示選項,try again重試,也可點擊查看詳細日誌,基本上是網絡不通,因為緩存(cached xxx.jar)不到國外庫的相應jar包導致:

技術分享圖片

4.Gradle默認配置在C盤下該用戶下的.gradle目錄,默認jar存放地址為C:\Users\(用戶名)\.gradle\caches\modules-2\files-2.1,可參考博文https://blog.csdn.net/chwshuang/article/details/52261940手動下載添加到Gradle已生成的對應目錄。

5.Gradle入門博客:https://www.jianshu.com/p/001abe1d8e95

6.Gradle倉庫配置:.gradle文件夾下添加腳本:

allprojects{
    repositories {
        def REPOSITORY_URL = ‘http://maven.aliyun.com/nexus/content/groups/public/‘
        all { ArtifactRepository repo ->
            if(repo instanceof MavenArtifactRepository){
                def url 
= repo.url.toString() if (url.startsWith(‘https://repo1.maven.org/maven2‘) || url.startsWith(‘https://jcenter.bintray.com/‘)) { project.logger.lifecycle "Repository ${repo.url} replaced by $REPOSITORY_URL." remove repo } } } maven { url REPOSITORY_URL } } }

命名為init.gradle,此為全局遠程倉庫配置。

每個項目的build.gradle文件中,可配置多個maven倉庫:

    repositories {
        mavenCentral()
        maven { url ‘http://maven.aliyun.com/nexus/content/groups/public/‘ }
        maven { url ‘https://repo.spring.io/libs-snapshot‘ }
    }

這樣可以分別從這幾個倉庫嘗試下載jar包,當然

io.spring.gradle:spring-build-conventions:0.0.15.RELEASE

這個包無論如何也找不到!

本地倉庫可配置環境變量GRADLE_USER_HOME,指定一個本地庫位置,下載的jar包會存儲在這裏.

參考博文:https://blog.csdn.net/x_iya/article/details/75040806

https://www.cnblogs.com/dwb91/p/6523541.html

這裏支持阿裏倉庫按artifactId,groupId查詢:http://maven.aliyun.com/mvn/search

IDEA引入Gradle工程小記