Gradle打jar包到本地maven倉庫和使用

一.Gradle打包

在需要打包的module的build.gradle中添加如下代碼:

group "項目groupId"//如:group "com.zcx.library"
version "版本號"//如:version "1.0.0"
uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: uri('輸入目錄名'))//如:repository(url: uri('../repo'))
        }
    }
}

同步之後在gradle中找到對應的module的uploadArchives執行,或者直接cmd cd到項目目錄執行gradlew uploadArchives命令.
在這裏插入圖片描述
執行完後,在剛指定的目錄生成項目的maven文件和jar包.

二.Gradle使用

1.Gradle插件依賴

如果是插件,在項目的根目錄的build.gradle中的buildscript的repositories中添加maven {url uri(‘剛寫maven的絕對目錄’)},然後在dependencies 中添加插件,如下

buildscript {
    repositories {
        maven {url uri('本地maven倉庫絕對地址')}//如:maven {url uri('D:\\maven\\repo')}
    }
    dependencies {
    	classpath '項目groupId:module名:版本號'//如:classpath 'com.zcx.library:library:1.0.0'
    }
}

1.普通依賴

如果是普通依賴,在項目的根目錄的build.gradle中的allprojects的repositories中添加maven {url uri(‘剛寫maven的絕對目錄’)},如下

allprojects {
    repositories {
        maven {url uri('本地maven倉庫絕對地址')}//如:maven {url uri('D:\\maven\\repo')}
    }
}

然後在你需要使用的module的build.gradle中將依賴添加到dependencies中,如下:

dependencies {
	implementation '項目groupId:module名:版本號'//如:implementation 'com.zcx.library:library:1.0.0'
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章