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