build.gradle 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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.13',
  12. mybatisSpringVersion = '2.1.1',
  13. mybatisSpringBootStarterVersion = '2.3.1',
  14. springVersion = '5.3.15',
  15. springBootVersion = '2.5.3',
  16. springCloudVersion = '3.1.1',
  17. jsqlparserVersion = '4.6',
  18. junitVersion = '5.9.0',
  19. ]
  20. lib = [
  21. "kotlin-reflect" : "org.jetbrains.kotlin:kotlin-reflect:1.9.0",
  22. "kotlin-stdlib-jdk8" : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.0",
  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.2",
  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: ['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.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.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.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. testImplementation "${lib["logback-classic"]}"
  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. // 控制台直接执行 `gradle licenseMain` 或者 `gradle licenseFormatMain`
  129. // 前者是检查 main 源码的 licence 情况,后者是在 main 源码文件上 format license
  130. // 因为不打算在 test 代码上添加 licence, 所以不使用 licenseTest 和 licenseFormatTest 这俩
  131. license {
  132. encoding = "UTF-8"
  133. header = rootProject.file("license.txt")
  134. includes(["**/*.java", "**/*.kt"])
  135. mapping {
  136. java = "SLASHSTAR_STYLE"
  137. kt = "SLASHSTAR_STYLE"
  138. }
  139. ignoreFailures = true
  140. ext.year = Calendar.getInstance().get(Calendar.YEAR)
  141. }
  142. //noinspection GroovyAssignabilityCheck
  143. task sourcesJar(type: Jar) {
  144. archiveClassifier = 'sources'
  145. from sourceSets.main.allSource
  146. }
  147. javadoc {
  148. afterEvaluate {
  149. configure(options) {
  150. encoding "UTF-8"
  151. charSet 'UTF-8'
  152. author true
  153. version true
  154. failOnError false
  155. links "http://docs.oracle.com/javase/8/docs/api"
  156. }
  157. }
  158. }
  159. test {
  160. dependsOn("cleanTest", "generatePomFileForMavenJavaPublication")
  161. useJUnitPlatform()
  162. // 增加jvm参数不是一个很好的处理方案,最好还是只用java8下跑,下面只是兼容运行一下,但在高版本jdk下还有很多第三方反射库存在问题(等待完全升级)
  163. // 部分测试用例如果需要在高版本java下运行用@EnabledOnJre
  164. // 例如: https://github.com/cglib/cglib/issues/191
  165. // if (JavaVersion.current().isJava9Compatible()) {
  166. // jvmArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED",
  167. // "--add-opens", "java.base/java.util=ALL-UNNAMED",
  168. // "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED"]
  169. // }
  170. exclude("**/phoenix/**")
  171. exclude("**/postgresql/**")
  172. // exclude("**/generator/**")
  173. }
  174. task cleanBuildDir(type: Delete) {
  175. delete "${projectDir}/out"
  176. }
  177. tasks.clean.dependsOn(cleanBuildDir)
  178. task javadocJar(type: Jar) {
  179. archiveClassifier = 'javadoc'
  180. from javadoc
  181. }
  182. tasks.whenTaskAdded { task ->
  183. if (task.name.contains('signMavenJavaPublication')) {
  184. task.enabled = new File(project.property('signing.secretKeyRingFile') as String).isFile()
  185. }
  186. }
  187. publishing {
  188. repositories {
  189. maven {
  190. def userName = System.getProperty("un")
  191. def passWord = System.getProperty("ps")
  192. def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
  193. def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
  194. url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
  195. credentials {
  196. username userName
  197. password passWord
  198. }
  199. }
  200. }
  201. publications {
  202. mavenJava(MavenPublication) {
  203. from components.java
  204. artifact sourcesJar
  205. artifact javadocJar
  206. pom {
  207. name = 'mybatis-plus'
  208. packaging 'jar'
  209. description = 'An enhanced toolkit of Mybatis to simplify development.'
  210. url = 'https://github.com/baomidou/mybatis-plus'
  211. scm {
  212. connection = 'scm:git@github.com:Codearte/gradle-nexus-staging-plugin.git'
  213. developerConnection = 'scm:git@github.com:Codearte/gradle-nexus-staging-plugin.git'
  214. url = 'https://github.com/baomidou/mybatis-plus'
  215. }
  216. licenses {
  217. license {
  218. name = 'The Apache License, Version 2.0'
  219. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  220. }
  221. }
  222. developers {
  223. developer {
  224. id = 'baomidou'
  225. name = 'hubin'
  226. email = 'jobob@qq.com'
  227. }
  228. }
  229. withXml {
  230. def root = asNode()
  231. root.dependencies.'*'.findAll {
  232. def d = it
  233. d.scope.text() == 'runtime' && project.configurations.findByName("implementation").allDependencies.find { dep ->
  234. dep.name == it.artifactId.text()
  235. }.each() {
  236. d.scope*.value = 'compile'
  237. d.appendNode('optional', true)
  238. }
  239. }
  240. }
  241. }
  242. }
  243. }
  244. signing {
  245. sign publishing.publications.mavenJava
  246. }
  247. }
  248. }