国内资源
从JDK8升级到JDK11,看这篇就足够了

gradle升级7.1版本概要

1. apply from, url须是安全访问,有两种方式修改

  1. a. http --> https
  2. b. apply from: resources.text.fromInsecureUri("http://www.deepdraw.cn/internal/prelude.gradle")

2 . 本地运行,init.gradle修改如下:

  1. a. 阿里云仓库安全访问
  2. ext.ALIYUN_REPO_URL = 'http://maven.aliyun.com/nexus/content/groups/public/'
  3. 修改后:
  4. ext.ALIYUN_REPO_URL = 'https://maven.aliyun.com/nexus/content/groups/public/'
  5. b. 深绘仓库安全访问
  6. maven {
  7. url DEEPDRAW_REPO_URL
  8. credentials {
  9. username DEEPDRAW_REPO_ACCOUNT
  10. password DEEPDRAW_REPO_PWD
  11. }
  12. }
  13. 修改后:
  14. maven {
  15. allowInsecureProtocol = true
  16. url DEEPDRAW_REPO_URL
  17. credentials {
  18. username DEEPDRAW_REPO_ACCOUNT
  19. password DEEPDRAW_REPO_PWD
  20. }
  21. }

3. 外部引用jar包与gradle引用冲突

打包时WEB-INF/libs中依赖模块名与gradle引入依赖冲突,提示Entry duplicate, 目前解决方案为删除libs中的外部依赖统一由gradle引入:

  1. 冲突模块:
  2. a. ognl-3.0.6
  3. b. commons-lang-2.6

4. testCompile -> testImplementation

  1. testCompile group: 'junit', name: 'junit', version: '4.12'
  2. 修改后:
  3. testImplementation 'junit:junit:4.12'

5. plugins中插件版本过低无法引入

  1. a. 更新插件版本
  2. b. 外部引入插件jar包,并在buildscript中声明
  3. buildscript {
  4. ...
  5. dependencies {
  6. classpath files("libs/gradle-js-plugin-2.14.1.jar")
  7. }
  8. }
  9. c. 寻找替代插件

6. compile -> implementation

  1. compile已废弃,替换为implementation
  1. compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.25'
  2. 修改后:
  3. implementation 'mysql:mysql-connector-java:5.1.25'

7. ant编译

  1. compile, runtime等已经废弃过时
  2. compile -> compileClasspath, runtime -> runtimeClasspath
  3. 如: classpath: configurations.compile.asPath)
  4. 修改后: classpath: configurations.compileClasspath.asPath)

8. testCompile配置问题

testImplementation引入后需要显式配置testCompile,否则无法找到测试类

  1. configurations {
  2. testCompile
  3. }

模块化项目只需要在subprojects中添加该配置即可

9. 过时配置或参数解决,编译参数添加”—warning-mode all”找到过时参数然后更新

10 . 对于推送jar包项目uploadArchives废弃的处理

  1. apply plugin: 'maven-publish'
  2. publishing {
  3. publications {
  4. maven(MavenPublication) {
  5. groupId = 'cn.deepdraw'
  6. artifactId = 'product-import-api'
  7. version = version
  8. }
  9. }
  10. repositories {
  11. maven {
  12. allowInsecureProtocol = true
  13. url DEEPDRAW_REPO_URL
  14. credentials {
  15. username DEEPDRAW_REPO_ACCOUNT
  16. password DEEPDRAW_REPO_PWD
  17. }
  18. }
  19. }
  20. }

11. 生成本地Pom文件

Maven Publish Plugin#Tasks
— generatePomFileForPubNamePublication
GenerateMavenPom

  1. task writePom {
  2. pom {}.writeTo(pomPath)
  3. }

修改为

  1. task writePom {
  2. model {
  3. tasks.generatePomFileForMavenPublication {
  4. destination = file(pomPath)
  5. }
  6. }
  7. }

12. JacocoReportBase

classDirectories为只读
使用getClassDirectories().setFrom()代替

jdk11升级总结

build.gradle

  • 增加依赖(取决于服务会不会用到)
  1. compile('javax.xml.bind:jaxb-api:2.3.1')
  2. compile('org.glassfish.jaxb:jaxb-core:2.3.0.1')
  3. compile('org.javassist:javassist:3.27.0-GA')
  • 所有jdk 1.8改为11

Dockfile

  • 修改tomcat
  1. registry.cn-hangzhou.aliyuncs.com/deepdraw-base/tomcat9-jdk11

Jenkinsfile

  • 修改jdk
  1. tools {
  2. jdk 'jdk11'
  3. }

遇到的问题

  • 无法读取dubbo中方法(ClassDefNotFound)

原因:二进制文件无法被读取

解决方案:增加依赖compile(‘org.javassist:javassist:3.27.0-GA’)

主系统JDK升级

  1. plugins {
  2. id 'war'
  3. id 'java'
  4. id 'eclipse'
  5. }
  6. ext {
  7. projectName = 'discoverer'
  8. setPropertyDefaultValue('env', 'local')
  9. configDir = 'src/main/resources/configurations'
  10. allInOneProperties = "$buildDir/tmp/allinone.properties"
  11. springVersion = '4.3.8.RELEASE'
  12. }
  13. repositories {
  14. mavenCentral()
  15. }
  16. configurations {
  17. ajc
  18. aspects
  19. aspectCompile
  20. compile {
  21. extendsFrom aspects
  22. }
  23. }
  24. compileJava {
  25. sourceCompatibility = 11
  26. targetCompatibility = 11
  27. doLast {
  28. ant.taskdef(resource: "org/aspectj/tools/ant/taskdefs/aspectjTaskdefs.properties",
  29. classpath: configurations.ajc.asPath)
  30. ant.iajc(source: '1.8', target: '1.8',
  31. destDir: sourceSets.main.output.classesDirs[0].absolutePath,
  32. maxmem: '512m', fork: 'true', aspectPath: configurations.aspects.asPath,
  33. inPath: 'libs/soomey.jar', sourceRootCopyFilter: '**/.git/*,**/*.java',
  34. classpath: configurations.compile.asPath) {
  35. sourceroots {
  36. sourceSets.main.java.srcDirs.each {
  37. pathelement(location:it.absolutePath)
  38. }
  39. }
  40. }
  41. }
  42. }
  43. task packProperties {
  44. doLast {
  45. delete allInOneProperties
  46. def props = readProps(configDir)
  47. writeProps(props, allInOneProperties)
  48. if (env != 'local') {
  49. // 线上环境需要用线上的配置参数覆盖一遍
  50. props = readProps(configDir + '/env/' + env)
  51. writeProps(props, allInOneProperties)
  52. }
  53. }
  54. }
  55. task decryptProperties(type: Exec) {
  56. if (System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')) {
  57. commandLine 'cmd', '/c', 'blackbox_postdeploy'
  58. } else {
  59. // TODO,现在线上服务器默认gpg版本还是gpg,因此暂时显式制定gpg为gpg2
  60. commandLine 'sh', '-c', 'GPG=gpg2 blackbox_postdeploy'
  61. }
  62. }
  63. decryptProperties.onlyIf { env != 'local' }
  64. war {
  65. // 用环境特有的配置文件,而不用本地的
  66. processResources {
  67. exclude '**/configurations/*.properties'
  68. exclude '**/configurations/env/**'
  69. }
  70. from(allInOneProperties, {
  71. into 'WEB-INF/classes/configurations'
  72. })
  73. // web.xml和spring-servlet.xml没有在资源管理体系下,需要显式拷贝
  74. from("webapp/WEB-INF", {
  75. include 'web.xml', 'spring-servlet.xml'
  76. into 'WEB-INF'
  77. })
  78. baseName projectName
  79. // 直接拷贝到webapp目录下,方便发布
  80. destinationDir file('webapp')
  81. }
  82. war.dependsOn decryptProperties, packProperties, test
  83. // 先执行clean命令来清除编译缓存,这样会比较慢,但是更稳定
  84. // task release(dependsOn: [compileJava, war]) {
  85. task release(dependsOn: [clean, compileJava, war]) {
  86. }
  87. dependencies {
  88. ajc 'org.aspectj:aspectjtools:1.9.4'
  89. providedCompile fileTree('libs').include('*.jar')
  90. providedCompile 'javax.servlet:javax.servlet-api:3.0.1'
  91. compile fileTree('webapp/WEB-INF/lib').include('*.jar')
  92. compile 'cn.deepdraw:deepdraw-framework-core:0.0.1'
  93. compile 'cn.deepdraw:deepdraw-framework-image:0.0.1'
  94. compile group: 'org.springframework', name: 'spring-core', version: "$springVersion"
  95. compile group: 'org.springframework', name: 'spring-beans', version: "$springVersion"
  96. compile group: 'org.springframework', name: 'spring-context', version: "$springVersion"
  97. compile group: 'org.springframework', name: 'spring-context-support', version: "$springVersion"
  98. compile group: 'org.springframework', name: 'spring-expression', version: "$springVersion"
  99. compile group: 'org.springframework', name: 'spring-web', version: "$springVersion"
  100. compile group: 'org.springframework', name: 'spring-webmvc', version: "$springVersion"
  101. compile group: 'org.springframework', name: 'spring-jdbc', version: "$springVersion"
  102. compile group: 'org.springframework', name: 'spring-test', version: "$springVersion"
  103. compile group: 'org.springframework', name: 'spring-orm', version: "$springVersion"
  104. compile group: 'org.hibernate', name: 'hibernate-core', version: '5.2.17.Final'
  105. compile group: 'com.alibaba', name: 'fastjson', version: '1.1.30'
  106. compile 'com.fasterxml.jackson.core:jackson-core:2.8.9'
  107. compile 'com.fasterxml.jackson.core:jackson-databind:2.8.9'
  108. compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.9'
  109. compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.9.6'
  110. testCompile group: 'junit', name: 'junit', version: '4.12'
  111. testCompile group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
  112. testCompile group: 'org.hamcrest', name: 'java-hamcrest', version: '2.0.0.0'
  113. }
  114. def setPropertyDefaultValue(propertyName, defaultValue) {
  115. if (!project.hasProperty(propertyName)) {
  116. ext[propertyName] = defaultValue
  117. }
  118. }
  119. def readProps(dir) {
  120. def props = new Properties()
  121. fileTree(dir: dir, include: '*.properties')
  122. .each{file ->
  123. file.withInputStream {props.load(it)}
  124. }
  125. return props
  126. }
  127. def writeProps(props, targetPath) {
  128. ant.propertyfile(file: targetPath) {
  129. props.each { key, val ->
  130. entry(key: key, value: val)
  131. }
  132. }
  133. }