gradle配置maven仓库

Maven配置

  • 在gradle(kts)中配置maven:

    build.gradle.kts

//仓库配置
repositories {
    //mavenLocal { setUrl("file://${project.rootDir}/lib") }
    //首先去本地仓库找
    mavenLocal()
    //然后去阿里仓库找
    // build.gradle:
    // maven { url "http://maven.aliyun.com/nexus/content/groups/public/" }

    // build.gradle.kts:
    maven { url = uri("https://repo.spring.io/release") }
    maven {
        isAllowInsecureProtocol = true
        setUrl("http://maven.aliyun.com/nexus/content/groups/public/")
    }
    maven {
        isAllowInsecureProtocol = true
        url = uri("https://maven.aliyun.com/repository/public") }
    maven {
        isAllowInsecureProtocol = true
        url = uri("https://maven.aliyun.com/repository/google") }
    maven {
        isAllowInsecureProtocol = true
        url = uri("https://maven.aliyun.com/repository/gradle-plugin") }
    maven {
        isAllowInsecureProtocol = true
        url = uri("https://maven.aliyun.com/repository/spring-plugin") }
    maven {
        isAllowInsecureProtocol = true
        url = uri("https://maven.aliyun.com/repository/apache-snapshots") }
    maven {
        isAllowInsecureProtocol = true
        url = uri("http://oss.jfrog.org/artifactory/oss-snapshot-local/") }
    google()
    jcenter()
    //最后从maven中央仓库找
    mavenCentral()
}
  • 在gradle(groovy)中配置maven:

    build.gradle

//仓库配置
repositories {
    //mavenLocal { setUrl("file://${project.rootDir}/lib") }
    //首先去本地仓库找
    mavenLocal()
    //然后去阿里仓库找
    // build.gradle.kts:
    //maven {
    //    isAllowInsecureProtocol = true
    //    setUrl("http://maven.aliyun.com/nexus/content/groups/public/")
    //}

    // build.gradle:
    maven { 
        setAllowInsecureProtocol(true)
        url "https://repo.spring.io/release" 
    }
    maven {
        //isAllowInsecureProtocol = true
        setAllowInsecureProtocol(true)
        url "http://maven.aliyun.com/nexus/content/groups/public/"
    }
    maven {
        //isAllowInsecureProtocol = true
        setAllowInsecureProtocol(true)
        url "https://maven.aliyun.com/repository/public"
    }
    maven {
        //isAllowInsecureProtocol = true
        setAllowInsecureProtocol(true)
        url "https://maven.aliyun.com/repository/google" }
    maven {
        //isAllowInsecureProtocol = true
        setAllowInsecureProtocol(true)
        url "https://maven.aliyun.com/repository/gradle-plugin" }
    maven {
        //isAllowInsecureProtocol = true
        setAllowInsecureProtocol(true)
        url "https://maven.aliyun.com/repository/spring-plugin" }
    maven {
        //isAllowInsecureProtocol = true
        setAllowInsecureProtocol(true)
        url "https://maven.aliyun.com/repository/apache-snapshots" }
    maven {
        //isAllowInsecureProtocol = true
        setAllowInsecureProtocol(true)
        url "http://oss.jfrog.org/artifactory/oss-snapshot-local/" }
    google()
    jcenter()
    //最后从maven中央仓库找
    mavenCentral()
}

IDEA配置代码模板

  1. 打开配置(settigs/preference)

  2. 搜索live(找到live template)

  3. 找到kotlin、gradle,分别做如下配置
    maven代码模板

  4. 配置完毕后,在编辑器中输入“mreps”,弹出提示,回车(Enter)。
    使用示例

原文地址:https://www.cnblogs.com/langkyeSir/p/15174846.html