zoukankan      html  css  js  c++  java
  • Gradle

    配置私服认证

    一般访问公共仓库配置如下:

    repositories {
        maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
    }
    

     私服有时会要求必须认证才可以访问公有仓库,那如下配置:

    repositories {
        maven {
            credentials {
            username 'username'
            password 'password'
            }
        url 'http://nexus.xxxxxx.com/nexus/content/groups/public' }
    }
    

      

    使用个人账号

    配置gradle的init:

    vim ~/.gradle/gradle.properties
    mavenUser=username
    mavenPass=password
    

      

    仓库变量引用:

    repositories {
            maven {
                credentials {
                    username "$mavenUser"
                    password "$mavenPass"
                }
                url 'http://nexus.xxxxxx.com/nexus/content/groups/public'
            }
        }
    

      

    依赖排除

    gradle中排除依赖有很多种方式,比如:
    在configuration中进行全局依赖排除:
    configurations {
         compile.exclude group: 'org.gradle.test.excludes', module: 'reports'
    }
     
    也可以在某个依赖内部进行细粒度的依赖排除:
    dependencies {
         compile("org.gradle.test.excludes:api:1.0"){
              exclude module: 'shared'
         }
    }
     
    排出某个依赖所有的传递依赖:
    dependencies {
         compile("org.gradle.test.excludes:api:1.0"){
        transitive = false
         }
    }
     
    但是做细粒度排除时有一个问题,如上写法,在发布到maven私服上时,依赖并没有被过滤掉。
    仔细尝试过gradle文档中说过的所有排除方式之后,发现,全局依赖可以在发布到maven私服的时候给每一项依赖都加上过滤。
    针对单项依赖进行的细粒度依赖排除如下写法也可以加上过滤:
    compile ("com.alibaba:dubbo:${dubboVersion}") {
        exclude group:'org.springframework', module: 'spring'
    }
    在这里,用的上传发布的工具是gradle官方推荐的工具:
    deployerJars "org.apache.maven.wagon:wagon-http:2.2"
    其内部存在一些bug。目前推荐使用上述写法。

    上传私服

    allprojects {
        apply plugin: 'java'
        apply plugin: 'idea'
        apply plugin: 'maven'
     
        idea {
            module {
                downloadSources=true
                downloadJavadoc=true
            }
        }
     
        configurations {
            provided
            compile.extendsFrom provided
            deployerJars
        }
     
        uploadArchives {
            repositories {
                mavenDeployer {
                    configuration = configurations.deployerJars
                    snapshotRepository(url: “xxx repository snapshots") {
                        authentication(userName: “username", password: “password")
                    }
                }
            }
        }
     
        task sourcesJar(type: Jar, dependsOn: classes) {
            classifier = 'sources'
            from sourceSets.main.allSource
        }
     
        task javadocJar(type: Jar, dependsOn: javadoc) {
            classifier = 'javadoc'
            from javadoc.destinationDir
        }
     
        artifacts {
            archives sourcesJar
            archives javadocJar
        }
     
        repositories {
            maven {
                name ‘xxx-repository'
                url ‘maven nexus repository'
            }
            mavenLocal()
        }
     
        group 'com.xxx'
        version '0.1.0-SNAPSHOT'
     
        sourceCompatibility = 1.7
    }
     
    subprojects {
        dependencies {
            deployerJars "org.apache.maven.wagon:wagon-http:2.2"
        }
    }

    从私服下载sourceJar&docJar

    在做到上传之后,在下载的时候也需要能够自动关联到source jar,javadoc jar。
    下载关联代码如下:
    选择idea插件,则配置如下:
        idea {
            module {
                downloadSources=true
                downloadJavadoc=true
            }
        }
    选择eclipse,则配置如下:
    eclipse {
         classpath {          
                downloadSources=true
                downloadJavadoc=true
         }
     } 

     获取最新版本的jar

    关于SNAPSHOT:
    一般开发过程中,版本都是SNAPSHOT版本的。在跨工程引用的时候,有2种办法控制获取最新版本的jar。第一种就是不断的更新版本,通过版本变更来获取最新版本的jar。另外一种就是声明变化版本,让gradle每次编译都去获取最新时间戳版本的jar。
    声明配置如下:
    configurations.all { // check for updates every build resolutionStrategy.cacheChangingModulesFor 0, 'seconds'} dependencies { compile group: "group", name: "projectA", version: "1.1-SNAPSHOT", changing: true}
  • 相关阅读:
    持续集成之Jenkins+sonar自动化部署04
    自动化部署03
    自动化部署02
    自动化部署01
    持续集成之代码质量管理-Sonar
    gitlab-ce安装01
    在Centos7.3安装Zabbix3.4.4服务端
    自动化运维之日志系统上线规范(十)
    自动化运维之日志系统Logstash实践(九)
    自动化运维之日志系统Logstash解耦实践(八)
  • 原文地址:https://www.cnblogs.com/asfeixue/p/8879798.html
Copyright © 2011-2022 走看看