build.gradle 9.5 KB

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