build.gradle 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. import java.text.SimpleDateFormat
  2. buildscript {
  3. repositories {
  4. maven { url "https://maven.aliyun.com/nexus/content/groups/public" }
  5. maven { url "http://maven.aliyun.com/nexus/content/repositories/gradle-plugin" }
  6. mavenCentral()
  7. maven { url "https://plugins.gradle.org/m2/" }
  8. }
  9. dependencies {
  10. //noinspection DifferentKotlinGradleVersion
  11. classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.30'
  12. classpath "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.15.0"
  13. }
  14. }
  15. ext {
  16. configuration = [
  17. javaVersion = JavaVersion.VERSION_1_8
  18. ]
  19. libraries = [
  20. mybatisVersion = '3.5.3',
  21. mybatisSpringVersion = '2.0.3',
  22. mybatisSpringBootStarterVersion = '2.1.1',
  23. springVersion = '5.2.1.RELEASE',
  24. springBootVersion = '2.2.1.RELEASE',
  25. jsqlparserVersion = '3.0',
  26. junitVersion = '5.5.2',
  27. ]
  28. lib = [
  29. "kotlin-reflect" : "org.jetbrains.kotlin:kotlin-reflect:1.3.50",
  30. "kotlin-stdlib-jdk8" : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.50",
  31. "jsqlparser" : "com.github.jsqlparser:jsqlparser:${jsqlparserVersion}",
  32. "mybatis" : "org.mybatis:mybatis:${mybatisVersion}",
  33. "mybatis-spring" : "org.mybatis:mybatis-spring:${mybatisSpringVersion}",
  34. "mybatis-thymeleaf" : "org.mybatis.scripting:mybatis-thymeleaf:1.0.1",
  35. "mybatis-freemarker" : "org.mybatis.scripting:mybatis-freemarker:1.2.0",
  36. "mybatis-velocity" : "org.mybatis.scripting:mybatis-velocity:2.1.0",
  37. "spring-context-support" : "org.springframework:spring-context-support:${springVersion}",
  38. "spring-jdbc" : "org.springframework:spring-jdbc:${springVersion}",
  39. "spring-tx" : "org.springframework:spring-tx:${springVersion}",
  40. "spring-web" : "org.springframework:spring-web:${springVersion}",
  41. "spring-aop" : "org.springframework:spring-aop:${springVersion}",
  42. "aspectjrt" : "org.aspectj:aspectjrt:1.9.4",
  43. "cglib" : "cglib:cglib:3.3.0",
  44. "lombok" : "org.projectlombok:lombok:1.18.10",
  45. "javax.servlet-api" : "javax.servlet:javax.servlet-api:4.0.1",
  46. "aspectjweaver" : "org.aspectj:aspectjweaver:1.9.4",
  47. "slf4j-api" : "org.slf4j:slf4j-api:1.7.28",
  48. "logback-classic" : "ch.qos.logback:logback-classic:1.2.3",
  49. //copy
  50. "mybatis-spring-boot-starter": "org.mybatis.spring.boot:mybatis-spring-boot-starter:${mybatisSpringBootStarterVersion}",
  51. //test
  52. "spring-test" : "org.springframework:spring-test:${springVersion}",
  53. "assertj-core" : "org.assertj:assertj-core:3.14.0",
  54. "junit-jupiter-api" : "org.junit.jupiter:junit-jupiter-api:${junitVersion}",
  55. "junit-jupiter-engine" : "org.junit.jupiter:junit-jupiter-engine:${junitVersion}",
  56. "fastjson" : "com.alibaba:fastjson:1.2.62",
  57. "jackson" : "com.fasterxml.jackson.core:jackson-databind:2.10.0",
  58. "lagarto" : "org.jodd:jodd-lagarto:5.0.7",
  59. //datasource
  60. "p6spy" : "p6spy:p6spy:3.8.6",
  61. "sqlserver" : "com.microsoft.sqlserver:sqljdbc4:4.0",
  62. "postgresql" : "org.postgresql:postgresql:42.2.8",
  63. "oracle" : fileTree(dir: 'libs', includes: ['ojdbc-11.2.0.3-jdk16.jar']),
  64. "dm" : fileTree(dir: 'libs', includes: ["jdbcDriver-18.jar"]),
  65. "kingbase" : fileTree(dir: 'libs', includes: ["kingbase8-8.2.0.jar"]),
  66. "h2" : "com.h2database:h2:1.4.197",
  67. "mysql" : "mysql:mysql-connector-java:8.0.15",
  68. "sqlite" : "org.xerial:sqlite-jdbc:3.27.2.1",
  69. //code generator
  70. "velocity" : "org.apache.velocity:velocity-engine-core:2.1",
  71. "freemarker" : "org.freemarker:freemarker:2.3.29",
  72. "beetl" : "com.ibeetl:beetl:2.9.8",
  73. "swagger-annotations" : "io.swagger:swagger-annotations:1.5.21"
  74. ]
  75. }
  76. allprojects {
  77. group = 'com.baomidou'
  78. version = "3.2.0"
  79. }
  80. description = "Mybatis 增强工具包 - 只做增强不做改变,简化CRUD操作"
  81. subprojects {
  82. apply plugin: 'java-library'
  83. apply plugin: 'signing'
  84. apply plugin: 'maven-publish'
  85. apply plugin: 'com.github.hierynomus.license'
  86. sourceCompatibility = "${javaVersion}"
  87. targetCompatibility = "${javaVersion}"
  88. tasks.withType(JavaCompile) {
  89. options.encoding = 'UTF-8'
  90. options.deprecation = true
  91. options.compilerArgs += ["-parameters"]
  92. }
  93. jar {
  94. afterEvaluate {
  95. manifest {
  96. attributes 'Implementation-Version': version
  97. attributes 'Built-Gradle': gradle.gradleVersion
  98. attributes 'Bundle-DocURL': 'https://mybatis.plus/'
  99. attributes 'Build-OS': System.getProperty("os.name")
  100. attributes 'Built-By': System.getProperty("user.name")
  101. attributes 'Build-Jdk': System.getProperty("java.version")
  102. attributes 'Build-Timestamp': new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())
  103. }
  104. }
  105. }
  106. license {
  107. encoding = "UTF-8"
  108. header = rootProject.file("license.txt")
  109. includes(["**/*.java", "**/*.kt"])
  110. exclude "**/*Test.java"
  111. exclude "**/TableNameParser.java"
  112. mapping "java", "SLASHSTAR_STYLE"
  113. mapping "kt", "SLASHSTAR_STYLE"
  114. ignoreFailures = true
  115. }
  116. repositories {
  117. mavenLocal()
  118. maven { url "https://maven.aliyun.com/repository/public" }
  119. maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
  120. jcenter()
  121. }
  122. dependencies {
  123. annotationProcessor "${lib.lombok}"
  124. compileOnly "${lib.lombok}"
  125. testAnnotationProcessor "${lib.lombok}"
  126. testCompileOnly "${lib.lombok}"
  127. testImplementation("${lib["assertj-core"]}")
  128. testImplementation("${lib["junit-jupiter-api"]}")
  129. testRuntimeOnly("${lib["junit-jupiter-engine"]}")
  130. testImplementation("org.mockito:mockito-junit-jupiter:3.1.0")
  131. testImplementation("${lib["lagarto"]}")
  132. testImplementation("${lib["logback-classic"]}")
  133. }
  134. //noinspection GroovyAssignabilityCheck
  135. task sourcesJar(type: Jar) {
  136. archiveClassifier = 'sources'
  137. from sourceSets.main.allJava
  138. }
  139. javadoc {
  140. afterEvaluate {
  141. configure(options) {
  142. encoding "UTF-8"
  143. charSet 'UTF-8'
  144. author true
  145. version true
  146. failOnError false
  147. links "http://docs.oracle.com/javase/8/docs/api"
  148. }
  149. }
  150. }
  151. test {
  152. dependsOn("cleanTest", "generatePomFileForMavenJavaPublication")
  153. useJUnitPlatform()
  154. exclude("**/generator/**")
  155. exclude("**/postgres/**")
  156. exclude("**/mysql/**")
  157. }
  158. task javadocJar(type: Jar) {
  159. archiveClassifier = 'javadoc'
  160. from javadoc
  161. }
  162. tasks.whenTaskAdded { task ->
  163. if (task.name.contains('signMavenJavaPublication')) {
  164. task.enabled = new File(project.property('signing.secretKeyRingFile') as String).isFile()
  165. }
  166. }
  167. publishing {
  168. repositories {
  169. maven {
  170. def userName = System.getProperty("un")
  171. def passWord = System.getProperty("ps")
  172. def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
  173. def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
  174. url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
  175. credentials {
  176. username userName
  177. password passWord
  178. }
  179. }
  180. }
  181. publications {
  182. mavenJava(MavenPublication) {
  183. from components.java
  184. artifact sourcesJar
  185. artifact javadocJar
  186. pom {
  187. name = 'mybatis-plus'
  188. packaging 'jar'
  189. description = 'An enhanced toolkit of Mybatis to simplify development.'
  190. url = 'https://github.com/baomidou/mybatis-plus'
  191. scm {
  192. connection = 'scm:git@github.com:Codearte/gradle-nexus-staging-plugin.git'
  193. developerConnection = 'scm:git@github.com:Codearte/gradle-nexus-staging-plugin.git'
  194. url = 'https://github.com/baomidou/mybatis-plus'
  195. }
  196. licenses {
  197. license {
  198. name = 'The Apache License, Version 2.0'
  199. url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
  200. }
  201. }
  202. developers {
  203. developer {
  204. id = 'baomidou'
  205. name = 'hubin'
  206. email = 'jobob@qq.com'
  207. }
  208. }
  209. withXml {
  210. def root = asNode()
  211. root.dependencies.'*'.findAll {
  212. def d = it
  213. d.scope.text() == 'runtime' && project.configurations.findByName("implementation").allDependencies.find { dep ->
  214. dep.name == it.artifactId.text()
  215. }.each() {
  216. d.scope*.value = 'compile'
  217. d.appendNode('optional', true)
  218. }
  219. }
  220. }
  221. }
  222. }
  223. }
  224. signing {
  225. sign publishing.publications.mavenJava
  226. }
  227. }
  228. }