build.gradle 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import java.time.LocalDateTime
  2. allprojects {
  3. group APP_GROUP
  4. version APP_VERSION
  5. }
  6. ext {
  7. configuration = [
  8. javaVersion = JavaVersion.VERSION_1_8
  9. ]
  10. libraries = [
  11. mybatisVersion = '3.5.10',
  12. mybatisSpringVersion = '2.0.7',
  13. mybatisSpringBootStarterVersion = '2.2.2',
  14. springVersion = '5.3.15',
  15. springBootVersion = '2.5.3',
  16. springCloudVersion = '3.1.1',
  17. jsqlparserVersion = '4.4', // 4.5 有bug
  18. junitVersion = '5.9.0',
  19. ]
  20. lib = [
  21. "kotlin-reflect" : "org.jetbrains.kotlin:kotlin-reflect:1.7.10",
  22. "kotlin-stdlib-jdk8" : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10",
  23. "jsqlparser" : "com.github.jsqlparser:jsqlparser:${jsqlparserVersion}",
  24. "mybatis" : "org.mybatis:mybatis:${mybatisVersion}",
  25. "mybatis-spring" : "org.mybatis:mybatis-spring:${mybatisSpringVersion}",
  26. "mybatis-thymeleaf" : "org.mybatis.scripting:mybatis-thymeleaf:1.0.3",
  27. "mybatis-freemarker" : "org.mybatis.scripting:mybatis-freemarker:1.2.3",
  28. "mybatis-velocity" : "org.mybatis.scripting:mybatis-velocity:2.1.1",
  29. "spring-context-support" : "org.springframework:spring-context-support:${springVersion}",
  30. "spring-jdbc" : "org.springframework:spring-jdbc:${springVersion}",
  31. "spring-tx" : "org.springframework:spring-tx:${springVersion}",
  32. "spring-web" : "org.springframework:spring-web:${springVersion}",
  33. "spring-aop" : "org.springframework:spring-aop:${springVersion}",
  34. "aspectjrt" : "org.aspectj:aspectjrt:1.9.9.1",
  35. "cglib" : "cglib:cglib:3.3.0",
  36. "imadcn" : "com.imadcn.framework:idworker:1.5.0",
  37. "spring-cloud-commons" : "org.springframework.cloud:spring-cloud-commons:${springCloudVersion}",
  38. "javax.servlet-api" : "javax.servlet:javax.servlet-api:4.0.1",
  39. "aspectjweaver" : "org.aspectj:aspectjweaver:1.9.9.1",
  40. "slf4j-api" : "org.slf4j:slf4j-api:1.7.36",
  41. //copy
  42. "mybatis-spring-boot-starter": "org.mybatis.spring.boot:mybatis-spring-boot-starter:${mybatisSpringBootStarterVersion}",
  43. //test
  44. "spring-test" : "org.springframework:spring-test:${springVersion}",
  45. "assertj-core" : "org.assertj:assertj-core:3.23.1",
  46. "junit-jupiter" : "org.junit.jupiter:junit-jupiter:${junitVersion}",
  47. "fastjson" : "com.alibaba:fastjson:2.0.11",
  48. "jackson" : "com.fasterxml.jackson.core:jackson-databind:2.13.3",
  49. "gson" : "com.google.code.gson:gson:2.9.1",
  50. "lagarto" : "org.jodd:jodd-lagarto:6.0.6",
  51. //datasource
  52. "p6spy" : "p6spy:p6spy:3.9.1",
  53. "sqlserver" : "com.microsoft.sqlserver:sqljdbc4:4.0",
  54. "postgresql" : "org.postgresql:postgresql:42.4.1",
  55. "oracle" : fileTree(dir: 'libs', includes: ['ojdbc-11.2.0.3-jdk16.jar']),
  56. "dm" : fileTree(dir: 'libs', includes: ["jdbcDriver-18.jar"]),
  57. "kingbase" : fileTree(dir: 'libs', includes: ["kingbase8-8.2.0.jar"]),
  58. "h2" : "com.h2database:h2:2.1.214",
  59. "mysql" : "mysql:mysql-connector-java:8.0.30",
  60. "sqlite" : "org.xerial:sqlite-jdbc:3.39.2.0",
  61. "firebird" : "org.firebirdsql.jdbc:jaybird:4.0.6.java8",
  62. //cache
  63. "mybatis-ehcache" : "org.mybatis.caches:mybatis-ehcache:1.2.1",
  64. "mybatis-redis" : "org.mybatis.caches:mybatis-redis:1.0.0-beta2",
  65. "mybatis-caffeine" : "org.mybatis.caches:mybatis-caffeine:1.0.0",
  66. //code generator
  67. "velocity" : "org.apache.velocity:velocity-engine-core:2.3",
  68. "freemarker" : "org.freemarker:freemarker:2.3.31",
  69. "beetl" : "com.ibeetl:beetl:3.7.0.RELEASE",
  70. "swagger-annotations" : "io.swagger:swagger-annotations:1.6.2",
  71. "enjoy" : "com.jfinal:enjoy:5.0.0",
  72. "logback-classic" : "ch.qos.logback:logback-classic:1.2.3",
  73. ]
  74. }
  75. description = "Mybatis 增强工具包 - 只做增强不做改变,简化CRUD操作"
  76. subprojects {
  77. apply plugin: 'java-library'
  78. apply plugin: 'signing'
  79. apply plugin: 'maven-publish'
  80. apply plugin: "io.freefair.lombok"
  81. apply plugin: 'com.github.hierynomus.license'
  82. sourceCompatibility = "${javaVersion}"
  83. targetCompatibility = "${javaVersion}"
  84. repositories {
  85. mavenLocal()
  86. maven { url "https://maven.aliyun.com/repository/public" }
  87. maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
  88. mavenCentral()
  89. }
  90. dependencies {
  91. testImplementation "${lib["assertj-core"]}"
  92. testImplementation "${lib["junit-jupiter"]}"
  93. testImplementation "org.mockito:mockito-junit-jupiter:4.6.1"
  94. testImplementation "${lib["lagarto"]}"
  95. }
  96. tasks.withType(JavaCompile) {
  97. options.encoding = 'UTF-8'
  98. options.warnings = false
  99. options.deprecation = true
  100. options.compilerArgs += ["-parameters"]
  101. }
  102. tasks.withType(GenerateModuleMetadata) {
  103. enabled = false
  104. }
  105. jar {
  106. into("META-INF/") {
  107. from rootProject.file("LICENSE")
  108. }
  109. into("META-INF/maven/$project.group/$project.name") {
  110. from { generatePomFileForMavenJavaPublication }
  111. rename ".*", "pom.xml"
  112. }
  113. afterEvaluate {
  114. manifest {
  115. attributes 'Implementation-Title': archiveBaseName
  116. attributes 'Implementation-Version': archiveVersion
  117. attributes 'Built-Gradle': gradle.gradleVersion
  118. attributes 'Bundle-DocURL': 'https://baomidou.com/'
  119. attributes 'Build-OS': System.getProperty("os.name")
  120. attributes 'Built-By': System.getProperty("user.name")
  121. attributes 'Build-Jdk': System.getProperty("java.version")
  122. attributes 'Build-Timestamp': LocalDateTime.now().format("yyyy-MM-dd HH:mm:ss")
  123. attributes 'Automatic-Module-Name': "${project.group}.${project.name.replaceAll("-", ".")}"
  124. }
  125. }
  126. }
  127. // 控制台直接执行 `gradle licenseMain` 或者 `gradle licenseFormatMain`
  128. // 前者是检查 main 源码的 licence 情况,后者是在 main 源码文件上 format license
  129. // 因为不打算在 test 代码上添加 licence, 所以不使用 licenseTest 和 licenseFormatTest 这俩
  130. license {
  131. encoding = "UTF-8"
  132. header = rootProject.file("license.txt")
  133. includes(["**/*.java", "**/*.kt"])
  134. mapping {
  135. java = "SLASHSTAR_STYLE"
  136. kt = "SLASHSTAR_STYLE"
  137. }
  138. ignoreFailures = true
  139. ext.year = Calendar.getInstance().get(Calendar.YEAR)
  140. }
  141. //noinspection GroovyAssignabilityCheck
  142. task sourcesJar(type: Jar) {
  143. archiveClassifier = 'sources'
  144. from sourceSets.main.allSource
  145. }
  146. javadoc {
  147. afterEvaluate {
  148. configure(options) {
  149. encoding "UTF-8"
  150. charSet 'UTF-8'
  151. author true
  152. version true
  153. failOnError false
  154. links "http://docs.oracle.com/javase/8/docs/api"
  155. }
  156. }
  157. }
  158. test {
  159. dependsOn("cleanTest", "generatePomFileForMavenJavaPublication")
  160. useJUnitPlatform()
  161. // 增加jvm参数不是一个很好的处理方案,最好还是只用java8下跑,下面只是兼容运行一下,但在高版本jdk下还有很多第三方反射库存在问题(等待完全升级)
  162. // 部分测试用例如果需要在高版本java下运行用@EnabledOnJre
  163. // 例如: https://github.com/cglib/cglib/issues/191
  164. if (JavaVersion.current().isJava9Compatible()) {
  165. jvmArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED",
  166. "--add-opens", "java.base/java.util=ALL-UNNAMED",
  167. "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED"]
  168. }
  169. exclude("**/phoenix/**")
  170. exclude("**/postgresql/**")
  171. exclude("**/generator/**")
  172. }
  173. task javadocJar(type: Jar) {
  174. archiveClassifier = 'javadoc'
  175. from javadoc
  176. }
  177. tasks.whenTaskAdded { task ->
  178. if (task.name.contains('signMavenJavaPublication')) {
  179. task.enabled = new File(project.property('signing.secretKeyRingFile') as String).isFile()
  180. }
  181. }
  182. publishing {
  183. repositories {
  184. maven {
  185. def userName = System.getProperty("un")
  186. def passWord = System.getProperty("ps")
  187. def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
  188. def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
  189. url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
  190. credentials {
  191. username userName
  192. password passWord
  193. }
  194. }
  195. }
  196. publications {
  197. mavenJava(MavenPublication) {
  198. from components.java
  199. artifact sourcesJar
  200. artifact javadocJar
  201. pom {
  202. name = 'mybatis-plus'
  203. packaging 'jar'
  204. description = 'An enhanced toolkit of Mybatis to simplify development.'
  205. url = 'https://github.com/baomidou/mybatis-plus'
  206. scm {
  207. connection = 'scm:git@github.com:Codearte/gradle-nexus-staging-plugin.git'
  208. developerConnection = 'scm:git@github.com:Codearte/gradle-nexus-staging-plugin.git'
  209. url = 'https://github.com/baomidou/mybatis-plus'
  210. }
  211. licenses {
  212. license {
  213. name = 'The Apache License, Version 2.0'
  214. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  215. }
  216. }
  217. developers {
  218. developer {
  219. id = 'baomidou'
  220. name = 'hubin'
  221. email = 'jobob@qq.com'
  222. }
  223. }
  224. withXml {
  225. def root = asNode()
  226. root.dependencies.'*'.findAll {
  227. def d = it
  228. d.scope.text() == 'runtime' && project.configurations.findByName("implementation").allDependencies.find { dep ->
  229. dep.name == it.artifactId.text()
  230. }.each() {
  231. d.scope*.value = 'compile'
  232. d.appendNode('optional', true)
  233. }
  234. }
  235. }
  236. }
  237. }
  238. }
  239. signing {
  240. sign publishing.publications.mavenJava
  241. }
  242. }
  243. }