此篇主要是在对现有项目构建由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中配置如下