gradle學習第二篇

 

   此篇主要是在對現有項目構建由maven切換gradle需要注意的地方

providedCompile 

    jar包/依賴代碼 僅在編譯的時候需要,但是在運行時不需要依賴

   前提:apply plugin: 'war'

 providedCompile 'com.hand:hap-core:3.5.4-RELEASE:classes'

     如果要使之生效,需要添加如下配置

//設置providedCompile
configurations {
    providedCompile
}

sourceSets.main.compileClasspath += configurations.providedCompile
sourceSets.test.compileClasspath += configurations.providedCompile
sourceSets.test.runtimeClasspath += configurations.providedCompile

uploadArchives 上傳war包及源碼 

前提:apply plugin: 'maven-publish'

         apply plugin: 'maven'

//打包源碼
task sourcesJar(type: Jar, dependsOn: classes) {
    classifier = 'sources'
    from sourceSets.main.allSource
}

artifacts {
    archives sourcesJar
}
//上傳資源配置
uploadArchives {
    repositories {
        mavenDeployer {
            //上傳資源到Maven私服
            def nexusUrl ="http://172.16.20.103:8081/repository/maven-releases/"
            if(project.version.endsWith("-SNAPSHOT")) {
                nexusUrl = "http://172.16.20.103:8081/repository/maven-snapshots/"
            }
            repository(url: nexusUrl) {
                authentication(userName:"admin",password:"admin123")
            }
            pom.version ="$project.version"
            pom.artifactId ="$project.name"
            pom.groupId ="$project.group"
        }
    }
}

profile命令指定配置文件

def env = System.getProperty("profile") ?: "dev"

//gradle war  -Dprofile=uat
sourceSets {
    main {
        resources {
            srcDirs = ["src/main/resources", "src/main/resources/profiles/$env"]
        }
    }
}

 

命令idea中配置如下

 

 overlays插件

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章