以pinyin4j-2.5.0.jar为例描述整个加载过程:
1. build脚本build.gradle中加载maven仓库3种方法:
- 加载中央仓库 (http://repo1.maven.org/maven2)
repositories {
mavenCentral()
}
- 加载本地maven缓存作为仓库
Gradle调用本地仓库,会根据用户目录下的.m2文件夹中的settings.xml(USER_HOME/.m2)进行调用。如果settings.xml不存在,gradle会通过用户目录下的.m2文件夹中的repository(USER_HOME/.m2/repository)进行调用。
repositories {
mavenLocal()
}
- 加载自定义maven仓库【示例】
repositories {
//no password
maven {
url "http://repo.mycompany.com/maven2"
}
}
repositories {
//username and password
maven {
credentials {
username 'user'
password 'password'
}
url "http://repo.mycompany.com/maven2"
}
}
- 加载需要的第三方包pinyin4j-2.5.0.jar
dependencies {
//groupId:artifactId:version
compile("com.belerweb:pinyin4j:2.5.0")
}
更多情况请参考: