- gradle升级7.1版本概要
- jdk11升级总结
- 主系统JDK升级">主系统JDK升级
gradle升级7.1版本概要
1. apply from, url须是安全访问,有两种方式修改
a. http --> httpsb. apply from: resources.text.fromInsecureUri("http://www.deepdraw.cn/internal/prelude.gradle")
2 . 本地运行,init.gradle修改如下:
a. 阿里云仓库安全访问ext.ALIYUN_REPO_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'修改后:ext.ALIYUN_REPO_URL = 'https://maven.aliyun.com/nexus/content/groups/public/'b. 深绘仓库安全访问maven {url DEEPDRAW_REPO_URLcredentials {username DEEPDRAW_REPO_ACCOUNTpassword DEEPDRAW_REPO_PWD}}修改后:maven {allowInsecureProtocol = trueurl DEEPDRAW_REPO_URLcredentials {username DEEPDRAW_REPO_ACCOUNTpassword DEEPDRAW_REPO_PWD}}
3. 外部引用jar包与gradle引用冲突
打包时WEB-INF/libs中依赖模块名与gradle引入依赖冲突,提示Entry duplicate, 目前解决方案为删除libs中的外部依赖统一由gradle引入:
冲突模块:a. ognl-3.0.6b. commons-lang-2.6
4. testCompile -> testImplementation
testCompile group: 'junit', name: 'junit', version: '4.12'修改后:testImplementation 'junit:junit:4.12'
5. plugins中插件版本过低无法引入
a. 更新插件版本b. 外部引入插件jar包,并在buildscript中声明buildscript {...dependencies {classpath files("libs/gradle-js-plugin-2.14.1.jar")}}c. 寻找替代插件
6. compile -> implementation
compile已废弃,替换为implementation
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.25'修改后:implementation 'mysql:mysql-connector-java:5.1.25'
7. ant编译
compile, runtime等已经废弃过时compile -> compileClasspath, runtime -> runtimeClasspath如: classpath: configurations.compile.asPath)修改后: classpath: configurations.compileClasspath.asPath)
8. testCompile配置问题
testImplementation引入后需要显式配置testCompile,否则无法找到测试类
configurations {testCompile}
模块化项目只需要在subprojects中添加该配置即可
9. 过时配置或参数解决,编译参数添加”—warning-mode all”找到过时参数然后更新
10 . 对于推送jar包项目uploadArchives废弃的处理
apply plugin: 'maven-publish'publishing {publications {maven(MavenPublication) {groupId = 'cn.deepdraw'artifactId = 'product-import-api'version = version}}repositories {maven {allowInsecureProtocol = trueurl DEEPDRAW_REPO_URLcredentials {username DEEPDRAW_REPO_ACCOUNTpassword DEEPDRAW_REPO_PWD}}}}
11. 生成本地Pom文件
Maven Publish Plugin#Tasks
— generatePomFileForPubNamePublication
— GenerateMavenPom
task writePom {pom {}.writeTo(pomPath)}
修改为
task writePom {model {tasks.generatePomFileForMavenPublication {destination = file(pomPath)}}}
12. JacocoReportBase
classDirectories为只读
使用getClassDirectories().setFrom()代替
jdk11升级总结
build.gradle
- 增加依赖(取决于服务会不会用到)
compile('javax.xml.bind:jaxb-api:2.3.1')compile('org.glassfish.jaxb:jaxb-core:2.3.0.1')compile('org.javassist:javassist:3.27.0-GA')
- 所有jdk 1.8改为11
Dockfile
- 修改tomcat
registry.cn-hangzhou.aliyuncs.com/deepdraw-base/tomcat9-jdk11
Jenkinsfile
- 修改jdk
tools {jdk 'jdk11'}
遇到的问题
- 无法读取dubbo中方法(ClassDefNotFound)
原因:二进制文件无法被读取
解决方案:增加依赖compile(‘org.javassist:javassist:3.27.0-GA’)
主系统JDK升级
plugins {id 'war'id 'java'id 'eclipse'}ext {projectName = 'discoverer'setPropertyDefaultValue('env', 'local')configDir = 'src/main/resources/configurations'allInOneProperties = "$buildDir/tmp/allinone.properties"springVersion = '4.3.8.RELEASE'}repositories {mavenCentral()}configurations {ajcaspectsaspectCompilecompile {extendsFrom aspects}}compileJava {sourceCompatibility = 11targetCompatibility = 11doLast {ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties",classpath: configurations.ajc.asPath)ant.iajc(source: '1.8', target: '1.8',destDir: sourceSets.main.output.classesDirs[0].absolutePath,maxmem: '512m', fork: 'true', aspectPath: configurations.aspects.asPath,inPath: 'libs/soomey.jar', sourceRootCopyFilter: '**/.git/*,**/*.java',classpath: configurations.compile.asPath) {sourceroots {sourceSets.main.java.srcDirs.each {pathelement(location:it.absolutePath)}}}}}task packProperties {doLast {delete allInOnePropertiesdef props = readProps(configDir)writeProps(props, allInOneProperties)if (env != 'local') {// 线上环境需要用线上的配置参数覆盖一遍props = readProps(configDir + '/env/' + env)writeProps(props, allInOneProperties)}}}task decryptProperties(type: Exec) {if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {commandLine 'cmd', '/c', 'blackbox_postdeploy'} else {// TODO,现在线上服务器默认gpg版本还是gpg,因此暂时显式制定gpg为gpg2commandLine 'sh', '-c', 'GPG=gpg2 blackbox_postdeploy'}}decryptProperties.onlyIf { env != 'local' }war {// 用环境特有的配置文件,而不用本地的processResources {exclude '**/configurations/*.properties'exclude '**/configurations/env/**'}from(allInOneProperties, {into 'WEB-INF/classes/configurations'})// web.xml和spring-servlet.xml没有在资源管理体系下,需要显式拷贝from("webapp/WEB-INF", {include 'web.xml', 'spring-servlet.xml'into 'WEB-INF'})baseName projectName// 直接拷贝到webapp目录下,方便发布destinationDir file('webapp')}war.dependsOn decryptProperties, packProperties, test// 先执行clean命令来清除编译缓存,这样会比较慢,但是更稳定// task release(dependsOn: [compileJava, war]) {task release(dependsOn: [clean, compileJava, war]) {}dependencies {ajc 'org.aspectj:aspectjtools:1.9.4'providedCompile fileTree('libs').include('*.jar')providedCompile 'javax.servlet:javax.servlet-api:3.0.1'compile fileTree('webapp/WEB-INF/lib').include('*.jar')compile 'cn.deepdraw:deepdraw-framework-core:0.0.1'compile 'cn.deepdraw:deepdraw-framework-image:0.0.1'compile group: 'org.springframework', name: 'spring-core', version: "$springVersion"compile group: 'org.springframework', name: 'spring-beans', version: "$springVersion"compile group: 'org.springframework', name: 'spring-context', version: "$springVersion"compile group: 'org.springframework', name: 'spring-context-support', version: "$springVersion"compile group: 'org.springframework', name: 'spring-expression', version: "$springVersion"compile group: 'org.springframework', name: 'spring-web', version: "$springVersion"compile group: 'org.springframework', name: 'spring-webmvc', version: "$springVersion"compile group: 'org.springframework', name: 'spring-jdbc', version: "$springVersion"compile group: 'org.springframework', name: 'spring-test', version: "$springVersion"compile group: 'org.springframework', name: 'spring-orm', version: "$springVersion"compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.17.Final'compile group: 'com.alibaba', name: 'fastjson', version: '1.1.30'compile 'com.fasterxml.jackson.core:jackson-core:2.8.9'compile 'com.fasterxml.jackson.core:jackson-databind:2.8.9'compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.9'compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.6'testCompile group: 'junit', name: 'junit', version: '4.12'testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'testCompile group: 'org.hamcrest', name: 'java-hamcrest', version: '2.0.0.0'}def setPropertyDefaultValue(propertyName, defaultValue) {if (!project.hasProperty(propertyName)) {ext[propertyName] = defaultValue}}def readProps(dir) {def props = new Properties()fileTree(dir: dir, include: '*.properties').each{file ->file.withInputStream {props.load(it)}}return props}def writeProps(props, targetPath) {ant.propertyfile(file: targetPath) {props.each { key, val ->entry(key: key, value: val)}}}
