build.gradle 9.6 KB

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