build.gradle 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. import java.time.LocalDateTime
  2. allprojects {
  3. group APP_GROUP
  4. version APP_VERSION
  5. }
  6. ext {
  7. configuration = [
  8. javaVersion = JavaVersion.VERSION_21
  9. ]
  10. libraries = [
  11. mybatisVersion = '3.5.15',
  12. mybatisSpringVersion = '2.1.2',
  13. mybatisSpringBootStarterVersion = '2.3.1',
  14. springVersion = '5.3.27',
  15. springBootVersion = '2.7.15',
  16. springBoot3Version = '3.2.0',
  17. springCloudVersion = '3.1.8',
  18. jsqlparserVersion = '4.9',
  19. junitVersion = '5.9.0',
  20. ]
  21. lib = [
  22. "kotlin-reflect" : "org.jetbrains.kotlin:kotlin-reflect:1.9.22",
  23. "kotlin-stdlib-jdk8" : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.22",
  24. "jsqlparser" : "com.github.jsqlparser:jsqlparser:${jsqlparserVersion}",
  25. "mybatis" : "org.mybatis:mybatis:${mybatisVersion}",
  26. "mybatis-spring" : "org.mybatis:mybatis-spring:${mybatisSpringVersion}",
  27. "mybatis-thymeleaf" : "org.mybatis.scripting:mybatis-thymeleaf:1.0.4",
  28. "mybatis-freemarker" : "org.mybatis.scripting:mybatis-freemarker:1.2.3",
  29. "mybatis-velocity" : "org.mybatis.scripting:mybatis-velocity:2.1.2",
  30. "spring-context-support" : "org.springframework:spring-context-support:${springVersion}",
  31. "spring-jdbc" : "org.springframework:spring-jdbc:${springVersion}",
  32. "spring-tx" : "org.springframework:spring-tx:${springVersion}",
  33. "spring-web" : "org.springframework:spring-web:${springVersion}",
  34. "spring-aop" : "org.springframework:spring-aop:${springVersion}",
  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.21",
  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.25.3",
  46. "junit-jupiter" : "org.junit.jupiter:junit-jupiter:${junitVersion}",
  47. "fastjson" : "com.alibaba:fastjson:2.0.44",
  48. "jackson" : "com.fasterxml.jackson.core:jackson-databind:2.16.1",
  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.7.1",
  55. "oracle" : fileTree(dir: 'libs', includes: ['ojdbc8.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.2.224",
  59. "mysql" : "mysql:mysql-connector-java:8.0.30",
  60. "sqlite" : "org.xerial:sqlite-jdbc:3.44.1.0",
  61. "firebird" : "org.firebirdsql.jdbc:jaybird:4.0.6.java8",
  62. //cache
  63. "mybatis-ehcache" : "org.mybatis.caches:mybatis-ehcache:1.2.3",
  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.32",
  69. "beetl" : "com.ibeetl:beetl:3.15.13.RELEASE",
  70. "swagger-annotations" : "io.swagger:swagger-annotations:1.6.12",
  71. "enjoy" : "com.jfinal:enjoy:5.1.3",
  72. "logback-classic" : "ch.qos.logback:logback-classic:1.4.11",
  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. lombok {
  85. version = "1.18.30"
  86. }
  87. compileJava {
  88. options.release = 8
  89. }
  90. repositories {
  91. mavenLocal()
  92. maven { url "https://maven.aliyun.com/repository/public" }
  93. maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
  94. mavenCentral()
  95. }
  96. dependencies {
  97. testImplementation "${lib["assertj-core"]}"
  98. testImplementation "${lib["junit-jupiter"]}"
  99. testImplementation "org.mockito:mockito-junit-jupiter:5.6.0"
  100. testImplementation "${lib["lagarto"]}"
  101. }
  102. tasks.withType(JavaCompile) {
  103. options.encoding = 'UTF-8'
  104. options.warnings = false
  105. options.deprecation = true
  106. options.compilerArgs += ["-parameters"]
  107. }
  108. tasks.withType(GenerateModuleMetadata) {
  109. enabled = false
  110. }
  111. jar {
  112. into("META-INF/") {
  113. from rootProject.file("LICENSE")
  114. }
  115. into("META-INF/maven/$project.group/$project.name") {
  116. from { generatePomFileForMavenJavaPublication }
  117. rename ".*", "pom.xml"
  118. }
  119. afterEvaluate {
  120. manifest {
  121. attributes 'Implementation-Title': archiveBaseName
  122. attributes 'Implementation-Version': archiveVersion
  123. attributes 'Built-Gradle': gradle.gradleVersion
  124. attributes 'Bundle-DocURL': 'https://baomidou.com/'
  125. attributes 'Build-OS': System.getProperty("os.name")
  126. attributes 'Built-By': System.getProperty("user.name")
  127. attributes 'Build-Jdk': System.getProperty("java.version")
  128. attributes 'Build-Timestamp': LocalDateTime.now().format("yyyy-MM-dd HH:mm:ss")
  129. attributes 'Automatic-Module-Name': "${project.group}.${project.name.replaceAll("-", ".")}"
  130. }
  131. }
  132. }
  133. // 控制台直接执行 `gradle licenseMain` 或者 `gradle licenseFormatMain`
  134. // 前者是检查 main 源码的 licence 情况,后者是在 main 源码文件上 format license
  135. // 因为不打算在 test 代码上添加 licence, 所以不使用 licenseTest 和 licenseFormatTest 这俩
  136. license {
  137. encoding = "UTF-8"
  138. header = rootProject.file("license.txt")
  139. includes(["**/*.java", "**/*.kt"])
  140. mapping {
  141. java = "SLASHSTAR_STYLE"
  142. kt = "SLASHSTAR_STYLE"
  143. }
  144. ignoreFailures = true
  145. ext.year = Calendar.getInstance().get(Calendar.YEAR)
  146. }
  147. //noinspection GroovyAssignabilityCheck
  148. task sourcesJar(type: Jar) {
  149. archiveClassifier = 'sources'
  150. from sourceSets.main.allSource
  151. }
  152. javadoc {
  153. afterEvaluate {
  154. configure(options) {
  155. encoding "UTF-8"
  156. charSet 'UTF-8'
  157. author true
  158. version true
  159. failOnError false
  160. links "http://docs.oracle.com/javase/8/docs/api"
  161. }
  162. }
  163. }
  164. test {
  165. dependsOn("cleanTest", "generatePomFileForMavenJavaPublication")
  166. useJUnitPlatform()
  167. // 增加jvm参数不是一个很好的处理方案,最好还是只用java8下跑,下面只是兼容运行一下,但在高版本jdk下还有很多第三方反射库存在问题(等待完全升级)
  168. // 部分测试用例如果需要在高版本java下运行用@EnabledOnJre
  169. // 例如: https://github.com/cglib/cglib/issues/191
  170. // if (JavaVersion.current().isJava9Compatible()) {
  171. // jvmArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED",
  172. // "--add-opens", "java.base/java.util=ALL-UNNAMED",
  173. // "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED"]
  174. // }
  175. exclude("**/phoenix/**")
  176. exclude("**/postgresql/**")
  177. // exclude("**/generator/**")
  178. }
  179. task cleanBuildDir(type: Delete) {
  180. delete "${projectDir}/out"
  181. }
  182. tasks.clean.dependsOn(cleanBuildDir)
  183. task javadocJar(type: Jar) {
  184. archiveClassifier = 'javadoc'
  185. from javadoc
  186. }
  187. tasks.whenTaskAdded { task ->
  188. if (task.name.contains('signMavenJavaPublication')) {
  189. task.enabled = new File(project.property('signing.secretKeyRingFile') as String).isFile()
  190. }
  191. }
  192. publishing {
  193. repositories {
  194. maven {
  195. def userName = System.getProperty("un")
  196. def passWord = System.getProperty("ps")
  197. def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
  198. def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
  199. url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
  200. credentials {
  201. username userName
  202. password passWord
  203. }
  204. }
  205. }
  206. publications {
  207. mavenJava(MavenPublication) {
  208. from components.java
  209. artifact sourcesJar
  210. artifact javadocJar
  211. pom {
  212. name = 'mybatis-plus'
  213. packaging 'jar'
  214. description = 'An enhanced toolkit of Mybatis to simplify development.'
  215. url = 'https://github.com/baomidou/mybatis-plus'
  216. scm {
  217. connection = 'scm:git@github.com:Codearte/gradle-nexus-staging-plugin.git'
  218. developerConnection = 'scm:git@github.com:Codearte/gradle-nexus-staging-plugin.git'
  219. url = 'https://github.com/baomidou/mybatis-plus'
  220. }
  221. licenses {
  222. license {
  223. name = 'The Apache License, Version 2.0'
  224. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  225. }
  226. }
  227. developers {
  228. developer {
  229. id = 'baomidou'
  230. name = 'hubin'
  231. email = 'jobob@qq.com'
  232. }
  233. }
  234. withXml {
  235. def root = asNode()
  236. root.dependencies.'*'.findAll {
  237. def d = it
  238. d.scope.text() == 'runtime' && project.configurations.findByName("implementation").allDependencies.find { dep ->
  239. dep.name == it.artifactId.text()
  240. }.each() {
  241. d.scope*.value = 'compile'
  242. d.appendNode('optional', true)
  243. }
  244. }
  245. }
  246. }
  247. }
  248. }
  249. signing {
  250. sign publishing.publications.mavenJava
  251. }
  252. }
  253. }