build.gradle.kts 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. import groovy.util.Node
  2. import groovy.util.NodeList
  3. buildscript {
  4. repositories {
  5. maven("https://plugins.gradle.org/m2/")
  6. }
  7. dependencies {
  8. classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.10")
  9. classpath("com.netflix.nebula:gradle-extra-configurations-plugin:3.0.3")
  10. }
  11. }
  12. plugins {
  13. `java-library`
  14. signing
  15. `maven-publish`
  16. }
  17. // versions
  18. val javaVersion = JavaVersion.VERSION_1_8
  19. val mybatisSpringVersion = "2.0.0"
  20. val mybatisVersion = "3.5.0"
  21. val springVersion = "5.1.4.RELEASE"
  22. val jsqlparserVersion = "1.3"
  23. val junitVersion = "5.4.0-RC1" // TODO 5.4.0 预计将与 2019-02-06 发布,届时应替换成正式版本
  24. val lombokVersion = "1.18.4"
  25. val cglibVersion = "3.2.6"
  26. // libs
  27. val lib = mapOf(
  28. "kotlin-reflect" to "org.jetbrains.kotlin:kotlin-reflect:1.3.10",
  29. "kotlin-stdlib-jdk8" to "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.10",
  30. "jsqlparser" to "com.github.jsqlparser:jsqlparser:$jsqlparserVersion",
  31. "mybatis-spring" to "org.mybatis:mybatis-spring:$mybatisSpringVersion",
  32. "mybatis" to "org.mybatis:mybatis:$mybatisVersion",
  33. "spring-context-support" to "org.springframework:spring-context-support:$springVersion",
  34. "spring-jdbc" to "org.springframework:spring-jdbc:$springVersion",
  35. "spring-tx" to "org.springframework:spring-tx:$springVersion",
  36. "spring-web" to "org.springframework:spring-web:$springVersion",
  37. "spring-aop" to "org.springframework:spring-aop:$springVersion",
  38. "cglib" to "cglib:cglib:$cglibVersion",
  39. "lombok" to "org.projectlombok:lombok:$lombokVersion",
  40. "javax.servlet-api" to "javax.servlet:javax.servlet-api:4.0.1",
  41. "aspectjweaver" to "org.aspectj:aspectjweaver:1.8.9",
  42. "mockito" to "org.mockito:mockito-core:2.13.0",
  43. "mybatis-ehcache" to "org.mybatis.caches:mybatis-ehcache:1.1.0",
  44. "slf4j-api" to "org.slf4j:slf4j-api:1.7.25",
  45. "logback-classic" to "ch.qos.logback:logback-classic:1.2.3",
  46. // test
  47. "spring-test" to "org.springframework:spring-test:$springVersion",
  48. "junit-jupiter-api" to "org.junit.jupiter:junit-jupiter-api:$junitVersion",
  49. "junit-jupiter-engine" to "org.junit.jupiter:junit-jupiter-engine:$junitVersion",
  50. "mockito-all" to "org.mockito:mockito-all:1.10.19",
  51. "fastjson" to "com.alibaba:fastjson:1.2.49",
  52. "jackson" to "com.fasterxml.jackson.core:jackson-databind:2.9.6",
  53. "tomcatjdbc" to "org.apache.tomcat:tomcat-jdbc:9.0.2",
  54. // datasource
  55. "hikaricp" to "com.zaxxer:HikariCP:2.7.0",
  56. "druid" to "com.alibaba:druid:1.0.29",
  57. "commons-dbcp2" to "org.apache.commons:commons-dbcp2:2.1.1",
  58. "sqlserver" to "com.microsoft.sqlserver:sqljdbc4:4.0",
  59. "postgresql" to "org.postgresql:postgresql:9.4.1212",
  60. "oracle" to fileTree("libs/ojdbc-11.2.0.3-jdk16.jar"),
  61. "h2" to "com.h2database:h2:1.4.194",
  62. "mysql" to "mysql:mysql-connector-java:5.1.38",
  63. // code generator
  64. "velocity" to "org.apache.velocity:velocity-engine-core:2.0",
  65. "freemarker" to "org.freemarker:freemarker:2.3.9",
  66. "beetl" to "com.ibeetl:beetl:2.9.6"
  67. )
  68. // ext
  69. extra["lib"] = lib
  70. allprojects {
  71. group = "com.baomidou"
  72. version = "3.0.8.3-SNAPSHOT"
  73. }
  74. description = "Mybatis 增强工具包 - 只做增强不做改变,简化CRUD操作"
  75. subprojects {
  76. // 插件
  77. apply(plugin = "org.gradle.java-library")
  78. apply(plugin = "org.gradle.maven-publish")
  79. apply(plugin = "org.gradle.signing")
  80. // Java 版本
  81. configure<JavaPluginConvention> {
  82. sourceCompatibility = javaVersion
  83. targetCompatibility = javaVersion
  84. }
  85. // 编译器配置
  86. tasks.withType<JavaCompile> {
  87. options.encoding = "UTF-8"
  88. options.isDeprecation = true
  89. options.compilerArgs.add("-parameters")
  90. }
  91. tasks.withType<Jar> {
  92. afterEvaluate {
  93. manifest {
  94. attributes["Implementation-Version"] = version
  95. }
  96. }
  97. }
  98. repositories {
  99. mavenLocal()
  100. maven("http://maven.aliyun.com/nexus/contencommons-dbcpt/groups/public/")
  101. maven("https://oss.sonatype.org/content/repositories/snapshots/")
  102. maven("http://www.cameliatk.jp/maven2/repository/thirdparty")
  103. jcenter()
  104. }
  105. dependencies {
  106. annotationProcessor("${lib["lombok"]}")
  107. compileOnly("${lib["lombok"]}")
  108. testAnnotationProcessor("${lib["lombok"]}")
  109. testCompileOnly("${lib["lombok"]}")
  110. testCompileOnly("${lib["mockito-all"]}")
  111. testImplementation("${lib["junit-jupiter-api"]}")
  112. testRuntimeOnly("${lib["junit-jupiter-engine"]}")
  113. testImplementation("org.mockito:mockito-junit-jupiter:2.23.4")
  114. }
  115. val sourcesJar by tasks.registering(Jar::class) {
  116. dependsOn(JavaPlugin.CLASSES_TASK_NAME)
  117. archiveClassifier.set("source")
  118. from(sourceSets["main"].allJava)
  119. }
  120. tasks.withType<Javadoc> {
  121. options.encoding = "UTF-8"
  122. isFailOnError = false
  123. (options as? StandardJavadocDocletOptions)?.also {
  124. it.charSet = "UTF-8"
  125. it.isAuthor = true
  126. it.isVersion = true
  127. it.links = listOf("https://docs.oracle.com/javase/8/docs/api")
  128. if (JavaVersion.current().isJava9Compatible) {
  129. it.addBooleanOption("html5", true)
  130. }
  131. }
  132. }
  133. tasks.withType<Test> {
  134. useJUnitPlatform()
  135. }
  136. val javadocJar by tasks.registering(Jar::class) {
  137. dependsOn(JavaPlugin.JAVADOC_TASK_NAME)
  138. archiveClassifier.set("javadoc")
  139. from(tasks["javadoc"])
  140. }
  141. tasks.whenTaskAdded {
  142. if (this.name.contains("signMavenJavaPublication")) {
  143. this.enabled = File(project.property("signing.secretKeyRingFile") as String).isFile
  144. }
  145. }
  146. publishing {
  147. repositories {
  148. maven {
  149. val userName = System.getProperty("un")
  150. val passWord = System.getProperty("ps")
  151. val releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
  152. val snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
  153. setUrl(if (version.toString().endsWith("RELEASE")) releasesRepoUrl else snapshotsRepoUrl)
  154. credentials {
  155. username = userName
  156. password = passWord
  157. }
  158. }
  159. }
  160. publications {
  161. register("mavenJava", MavenPublication::class) {
  162. pom {
  163. name.set("mybatis-plus")
  164. description.set("An enhanced toolkit of Mybatis to simplify development.")
  165. inceptionYear.set("2016")
  166. url.set("https://github.com/baomidou/mybatis-plus")
  167. artifactId = project.name
  168. groupId = "${project.group}"
  169. version = "${project.version}"
  170. packaging = "jar"
  171. organization {
  172. name.set("baomidou")
  173. }
  174. scm {
  175. connection.set("scm:git@github.com:Codearte/gradle-nexus-staging-plugin.git")
  176. developerConnection.set("scm:git@github.com:Codearte/gradle-nexus-staging-plugin.git")
  177. url.set("https://github.com/baomidou/mybatis-plus")
  178. }
  179. licenses {
  180. license {
  181. name.set("The Apache License, Version 2.0")
  182. url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
  183. }
  184. }
  185. developers {
  186. developer {
  187. id.set("baomidou")
  188. name.set("hubin")
  189. email.set("jobob@qq.com")
  190. }
  191. }
  192. withXml {
  193. val root = asNode()
  194. root["dependencies"].asNodeList().getAt("*").forEach {
  195. val dependency = it.asNode()
  196. if (dependency["scope"].asNodeList().text() == "runtime") {
  197. if (project.configurations.findByName("implementation")?.allDependencies?.none { dep ->
  198. dep.name == dependency["artifactId"].asNodeList().text()
  199. } == false) {
  200. dependency["scope"].asNodeList().forEach { it.asNode().setValue("compile") }
  201. dependency.appendNode("optional", true)
  202. }
  203. }
  204. }
  205. }
  206. }
  207. from(components["java"])
  208. artifact(sourcesJar.get())
  209. artifact(javadocJar.get())
  210. }
  211. }
  212. }
  213. signing {
  214. sign(publishing.publications.getByName("mavenJava"))
  215. }
  216. }
  217. fun Any?.asNode() = this as Node
  218. fun Any?.asNodeList() = this as NodeList