build.gradle 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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.16',
  12. mybatisSpringVersion = '2.1.2',
  13. mybatisSpringBootStarterVersion = '2.3.1',
  14. springVersion = '5.3.34',
  15. springBootVersion = '2.7.18',
  16. springBoot3Version = '3.2.4',
  17. springCloudVersion = '3.1.8',
  18. jsqlparserVersion = '4.9',
  19. junitVersion = '5.10.2',
  20. ]
  21. lib = [
  22. "kotlin-reflect" : "org.jetbrains.kotlin:kotlin-reflect:1.9.24",
  23. "kotlin-stdlib-jdk8" : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.24",
  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.6.0",
  37. "spring-cloud-commons" : "org.springframework.cloud:spring-cloud-commons:${springCloudVersion}",
  38. "aspectjweaver" : "org.aspectj:aspectjweaver:1.9.22.1",
  39. "slf4j-api" : "org.slf4j:slf4j-api:1.7.36",
  40. //copy
  41. "mybatis-spring-boot-starter": "org.mybatis.spring.boot:mybatis-spring-boot-starter:${mybatisSpringBootStarterVersion}",
  42. //test
  43. "spring-test" : "org.springframework:spring-test:${springVersion}",
  44. "assertj-core" : "org.assertj:assertj-core:3.25.3",
  45. "junit-jupiter" : "org.junit.jupiter:junit-jupiter:${junitVersion}",
  46. "fastjson" : "com.alibaba:fastjson:2.0.50",
  47. "jackson" : "com.fasterxml.jackson.core:jackson-databind:2.17.1",
  48. "gson" : "com.google.code.gson:gson:2.11.0",
  49. "lagarto" : "org.jodd:jodd-lagarto:6.0.6",
  50. //datasource
  51. "p6spy" : "p6spy:p6spy:3.9.1",
  52. "sqlserver" : "com.microsoft.sqlserver:sqljdbc4:4.0",
  53. "postgresql" : "org.postgresql:postgresql:42.7.3",
  54. "oracle" : fileTree(dir: 'libs', includes: ['ojdbc8.jar']),
  55. "dm" : fileTree(dir: 'libs', includes: ["jdbcDriver-18.jar"]),
  56. "h2" : "com.h2database:h2:2.2.224",
  57. "mysql" : "com.mysql:mysql-connector-j:8.4.0",
  58. "sqlite" : "org.xerial:sqlite-jdbc:3.45.3.0",
  59. "firebird" : "org.firebirdsql.jdbc:jaybird:5.0.4.java8",
  60. //cache
  61. "mybatis-caffeine" : "org.mybatis.caches:mybatis-caffeine:1.0.0",
  62. //code generator
  63. "velocity" : "org.apache.velocity:velocity-engine-core:2.3",
  64. "freemarker" : "org.freemarker:freemarker:2.3.32",
  65. "beetl" : "com.ibeetl:beetl:3.16.1.RELEASE",
  66. "swagger-annotations" : "io.swagger:swagger-annotations:1.6.14",
  67. "enjoy" : "com.jfinal:enjoy:5.1.3",
  68. "logback-classic" : "ch.qos.logback:logback-classic:1.5.6",
  69. ]
  70. }
  71. description = "Mybatis 增强工具包 - 只做增强不做改变,简化CRUD操作"
  72. subprojects {
  73. apply plugin: 'java-library'
  74. apply plugin: 'signing'
  75. apply plugin: 'maven-publish'
  76. apply plugin: "io.freefair.lombok"
  77. sourceCompatibility = "${javaVersion}"
  78. targetCompatibility = "${javaVersion}"
  79. lombok {
  80. version = "1.18.32"
  81. }
  82. compileJava {
  83. options.release = 8
  84. }
  85. repositories {
  86. mavenLocal()
  87. maven { url "https://maven.aliyun.com/repository/public" }
  88. maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
  89. mavenCentral()
  90. }
  91. dependencies {
  92. testImplementation "${lib["assertj-core"]}"
  93. testImplementation "${lib["junit-jupiter"]}"
  94. testImplementation "org.mockito:mockito-junit-jupiter:5.12.0"
  95. testImplementation "${lib["lagarto"]}"
  96. }
  97. tasks.withType(JavaCompile) {
  98. options.encoding = 'UTF-8'
  99. options.warnings = false
  100. options.deprecation = true
  101. options.compilerArgs += ["-parameters"]
  102. }
  103. tasks.withType(GenerateModuleMetadata) {
  104. enabled = false
  105. }
  106. jar {
  107. into("META-INF/") {
  108. from rootProject.file("LICENSE")
  109. }
  110. into("META-INF/maven/$project.group/$project.name") {
  111. from { generatePomFileForMavenJavaPublication }
  112. rename ".*", "pom.xml"
  113. }
  114. afterEvaluate {
  115. manifest {
  116. attributes 'Implementation-Title': archiveBaseName
  117. attributes 'Implementation-Version': archiveVersion
  118. attributes 'Built-Gradle': gradle.gradleVersion
  119. attributes 'Bundle-DocURL': 'https://baomidou.com/'
  120. attributes 'Build-OS': System.getProperty("os.name")
  121. attributes 'Built-By': System.getProperty("user.name")
  122. attributes 'Build-Jdk': System.getProperty("java.version")
  123. attributes 'Build-Timestamp': LocalDateTime.now().format("yyyy-MM-dd HH:mm:ss")
  124. attributes 'Automatic-Module-Name': "${project.group}.${project.name.replaceAll("-", ".")}"
  125. }
  126. }
  127. }
  128. //noinspection GroovyAssignabilityCheck
  129. task sourcesJar(type: Jar) {
  130. archiveClassifier = 'sources'
  131. from sourceSets.main.allSource
  132. }
  133. javadoc {
  134. afterEvaluate {
  135. configure(options) {
  136. encoding "UTF-8"
  137. charSet 'UTF-8'
  138. author true
  139. version true
  140. failOnError false
  141. links "http://docs.oracle.com/javase/8/docs/api"
  142. }
  143. }
  144. }
  145. test {
  146. dependsOn("cleanTest", "generatePomFileForMavenJavaPublication")
  147. useJUnitPlatform()
  148. // 增加jvm参数不是一个很好的处理方案,最好还是只用java8下跑,下面只是兼容运行一下,但在高版本jdk下还有很多第三方反射库存在问题(等待完全升级)
  149. // 部分测试用例如果需要在高版本java下运行用@EnabledOnJre
  150. // 例如: https://github.com/cglib/cglib/issues/191
  151. // if (JavaVersion.current().isJava9Compatible()) {
  152. // jvmArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED",
  153. // "--add-opens", "java.base/java.util=ALL-UNNAMED",
  154. // "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED"]
  155. // }
  156. exclude("**/phoenix/**")
  157. exclude("**/postgresql/**")
  158. // exclude("**/generator/**")
  159. }
  160. task cleanBuildDir(type: Delete) {
  161. delete "${projectDir}/out"
  162. }
  163. tasks.clean.dependsOn(cleanBuildDir)
  164. task javadocJar(type: Jar) {
  165. archiveClassifier = 'javadoc'
  166. from javadoc
  167. }
  168. tasks.whenTaskAdded { task ->
  169. if (task.name.contains('signMavenJavaPublication')) {
  170. task.enabled = new File(project.property('signing.secretKeyRingFile') as String).isFile()
  171. }
  172. }
  173. publishing {
  174. repositories {
  175. maven {
  176. def userName = System.getProperty("un")
  177. def passWord = System.getProperty("ps")
  178. def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
  179. def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
  180. url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
  181. credentials {
  182. username userName
  183. password passWord
  184. }
  185. }
  186. }
  187. publications {
  188. mavenJava(MavenPublication) {
  189. from components.java
  190. artifact sourcesJar
  191. artifact javadocJar
  192. pom {
  193. name = 'mybatis-plus'
  194. packaging 'jar'
  195. description = 'An enhanced toolkit of Mybatis to simplify development.'
  196. url = 'https://github.com/baomidou/mybatis-plus'
  197. scm {
  198. connection = 'scm:git@github.com:Codearte/gradle-nexus-staging-plugin.git'
  199. developerConnection = 'scm:git@github.com:Codearte/gradle-nexus-staging-plugin.git'
  200. url = 'https://github.com/baomidou/mybatis-plus'
  201. }
  202. licenses {
  203. license {
  204. name = 'The Apache License, Version 2.0'
  205. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  206. }
  207. }
  208. developers {
  209. developer {
  210. id = 'baomidou'
  211. name = 'hubin'
  212. email = 'jobob@qq.com'
  213. }
  214. }
  215. withXml {
  216. def root = asNode()
  217. root.dependencies.'*'.findAll {
  218. def d = it
  219. d.scope.text() == 'runtime' && project.configurations.findByName("implementation").allDependencies.find { dep ->
  220. dep.name == it.artifactId.text()
  221. }.each() {
  222. d.scope*.value = 'compile'
  223. d.appendNode('optional', true)
  224. }
  225. }
  226. }
  227. }
  228. }
  229. }
  230. signing {
  231. sign publishing.publications.mavenJava
  232. }
  233. }
  234. }