You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.gradle 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. import org.apache.tools.ant.filters.ReplaceTokens
  2. plugins {
  3. id "com.github.johnrengelman.shadow"
  4. id "de.undercouch.download"
  5. }
  6. sonarqube {
  7. properties {
  8. property 'sonar.projectName', "${projectTitle} :: Application"
  9. }
  10. }
  11. configurations {
  12. zip
  13. jsw
  14. scanner
  15. web
  16. shutdowner
  17. jdbc_mssql {
  18. transitive = false
  19. }
  20. jdbc_postgresql {
  21. transitive = false
  22. }
  23. jdbc_h2 {
  24. transitive = false
  25. }
  26. bundledPlugin {
  27. transitive = false
  28. }
  29. }
  30. jar.enabled = false
  31. shadowJar {
  32. baseName = 'sonar-application'
  33. classifier = null
  34. mergeServiceFiles()
  35. manifest {
  36. attributes('Main-Class': 'org.sonar.application.App')
  37. }
  38. }
  39. dependencies {
  40. // please keep list ordered
  41. compile 'org.slf4j:slf4j-api'
  42. compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client'
  43. compile project(':server:sonar-ce')
  44. compile project(':server:sonar-main')
  45. compile project(':server:sonar-process')
  46. compile project(':server:sonar-webserver')
  47. compile project(':sonar-core')
  48. compile project(path: ':sonar-plugin-api', configuration: 'shadow')
  49. compile project(':sonar-plugin-api-impl')
  50. compileOnly 'com.google.code.findbugs:jsr305'
  51. jsw 'tanukisoft:wrapper:3.2.3'
  52. scanner project(path: ':sonar-scanner-engine-shaded', configuration: 'shadow')
  53. web project(':server:sonar-web')
  54. shutdowner project(':sonar-shutdowner')
  55. jdbc_h2 'com.h2database:h2'
  56. jdbc_mssql 'com.microsoft.sqlserver:mssql-jdbc'
  57. jdbc_postgresql 'org.postgresql:postgresql'
  58. }
  59. // declare dependencies in configuration bundledPlugin to be packaged in lib/extensions
  60. apply from: 'bundled_plugins.gradle'
  61. task verifyElasticSearchDownload(type: Verify) {
  62. src new File(buildDir, "$elasticsearchDownloadUrlFile")
  63. algorithm 'SHA-512'
  64. checksum elasticsearchDownloadSha512
  65. }
  66. task downloadElasticSearch(type: Download) {
  67. def artifactoryUsername = System.env.'ARTIFACTORY_PRIVATE_USERNAME' ?: (project.hasProperty('artifactoryUsername') ? project.getProperty('artifactoryUsername') : '')
  68. def artifactoryPassword = System.env.'ARTIFACTORY_PRIVATE_PASSWORD' ?: (project.hasProperty('artifactoryPassword') ? project.getProperty('artifactoryPassword') : '')
  69. if (artifactoryUsername && artifactoryPassword) {
  70. src "$elasticsearchDownloadRepoxUrlPath$elasticsearchDownloadUrlFile"
  71. username artifactoryUsername
  72. password artifactoryPassword
  73. } else {
  74. src "$elasticsearchDownloadUrlPath$elasticsearchDownloadUrlFile"
  75. }
  76. dest "$buildDir/$elasticsearchDownloadUrlFile"
  77. onlyIfModified true
  78. finalizedBy verifyElasticSearchDownload
  79. }
  80. task zip(type: Zip, dependsOn: [configurations.compile, downloadElasticSearch, verifyElasticSearchDownload]) {
  81. duplicatesStrategy DuplicatesStrategy.EXCLUDE
  82. def archiveDir = "sonarqube-$project.version"
  83. into("${archiveDir}/") {
  84. from(file('src/main/assembly')) {
  85. exclude 'conf/sonar.properties'
  86. exclude 'conf/wrapper.conf'
  87. exclude 'elasticsearch-patch'
  88. }
  89. }
  90. from(tarTree(downloadElasticSearch.dest)) {
  91. eachFile { fcd ->
  92. def path = fcd.relativePath.segments - fcd.relativeSourcePath.segments + fcd.relativeSourcePath.segments.drop(1)
  93. fcd.relativePath = new RelativePath(true, *path)
  94. }
  95. into("${archiveDir}/elasticsearch")
  96. // elasticsearch script will be replaced by patched version below
  97. exclude '**/bin/elasticsearch'
  98. exclude '**/bin/elasticsearch-cli'
  99. exclude '**/bin/elasticsearch-keystore'
  100. exclude '**/bin/elasticsearch-node'
  101. exclude '**/bin/elasticsearch-shard'
  102. exclude '**/jdk/**'
  103. exclude '**/lib/tools/**'
  104. exclude '**/modules/aggs-matrix-stats/**'
  105. exclude '**/modules/geo/**'
  106. exclude '**/modules/ingest-common/**'
  107. exclude '**/modules/ingest-geoip/**'
  108. exclude '**/modules/ingest-user-agent/**'
  109. exclude '**/modules/kibana/**'
  110. exclude '**/modules/lang-expression/**'
  111. exclude '**/modules/lang-mustache/**'
  112. exclude '**/modules/mapper-extras/**'
  113. exclude '**/modules/rank-eval/**'
  114. exclude '**/modules/reindex/**'
  115. exclude '**/modules/repository-url/**'
  116. exclude '**/modules/tasks/**'
  117. exclude '**/modules/constant-keyword/**'
  118. exclude '**/modules/flattened/**'
  119. exclude '**/modules/frozen-indices/**'
  120. exclude '**/modules/mapper-version/**'
  121. exclude '**/modules/repositories-metering-api/**'
  122. exclude '**/modules/repository-encrypted/**'
  123. exclude '**/modules/search-business-rules/**'
  124. exclude '**/modules/searchable-snapshots/**'
  125. exclude '**/modules/snapshot-repo-test-kit/**'
  126. exclude '**/modules/spatial/**'
  127. exclude '**/modules/transform/**'
  128. exclude '**/modules/unsigned-long/**'
  129. exclude '**/modules/vectors/**'
  130. exclude '**/modules/wildcard/**'
  131. exclude '**/modules/x-pack-*/**'
  132. includeEmptyDirs = false
  133. }
  134. into("${archiveDir}/conf/") {
  135. from file('src/main/assembly/conf/sonar.properties')
  136. filter(ReplaceTokens, tokens: [
  137. 'searchDefaultHeapSize': '512MB',
  138. 'searchJavaOpts' : '-Xmx512m -Xms512m -XX:MaxDirectMemorySize=256m -XX:+HeapDumpOnOutOfMemoryError',
  139. 'ceDefaultHeapSize' : '512MB',
  140. 'ceJavaOpts' : '-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError',
  141. 'webDefaultHeapSize' : '512MB',
  142. 'webJavaOpts' : '-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError'
  143. ])
  144. }
  145. into("${archiveDir}/conf/") {
  146. from file('src/main/assembly/conf/wrapper.conf')
  147. filter(ReplaceTokens, tokens: [
  148. 'sqversion': version
  149. ])
  150. }
  151. into("${archiveDir}/elasticsearch/") {
  152. from file('src/main/assembly/elasticsearch-patch')
  153. include 'bin/elasticsearch'
  154. }
  155. // Create the empty dir (plugins) required by elasticsearch
  156. into("${archiveDir}/elasticsearch/") {
  157. from "$buildDir/elasticsearch"
  158. }
  159. into("${archiveDir}/lib/extensions/") {
  160. from configurations.bundledPlugin
  161. }
  162. into("${archiveDir}/lib/jsw/") {
  163. from configurations.jsw
  164. }
  165. into("${archiveDir}/lib/scanner/") {
  166. from configurations.scanner
  167. }
  168. into("${archiveDir}/lib/") {
  169. from shadowJar
  170. }
  171. into("${archiveDir}/web/") {
  172. duplicatesStrategy DuplicatesStrategy.FAIL
  173. // FIXME use configurations.web with correct artifacts
  174. from(tasks.getByPath(':server:sonar-web:yarn_run').outputs) { a ->
  175. if (official) {
  176. project(':private:branding').fileTree('src').visit { b ->
  177. if (!b.isDirectory()) {
  178. a.exclude b.relativePath.toString()
  179. }
  180. }
  181. }
  182. }
  183. if (official) {
  184. from project(':private:branding').file('src')
  185. }
  186. }
  187. into("${archiveDir}/lib/jdbc/mssql/") {
  188. from configurations.jdbc_mssql
  189. }
  190. into("${archiveDir}/lib/jdbc/postgresql/") {
  191. from configurations.jdbc_postgresql
  192. }
  193. into("${archiveDir}/lib/jdbc/h2/") {
  194. from configurations.jdbc_h2
  195. }
  196. into("${archiveDir}/lib/") {
  197. from configurations.shutdowner
  198. }
  199. }
  200. // Create the empty dir required by elasticsearch
  201. zip.doFirst {
  202. new File(buildDir, 'elasticsearch/plugins').mkdirs()
  203. }
  204. // Check the size of the archive
  205. zip.doLast {
  206. def minLength = 270000000
  207. def maxLength = 291000000
  208. def length = archiveFile.get().asFile.length()
  209. if (length < minLength)
  210. throw new GradleException("$archiveName size ($length) too small. Min is $minLength")
  211. if (length > maxLength)
  212. throw new GradleException("$distsDir/$archiveName size ($length) too large. Max is $maxLength")
  213. }
  214. assemble.dependsOn zip
  215. // the script start.sh unpacks OSS distribution into $buildDir/distributions/sonarqube-oss.
  216. // This directory should be deleted when the zip is changed.
  217. task cleanLocalUnzippedDir(dependsOn: zip) {
  218. def unzippedDir = file("$buildDir/distributions/sonarqube-$version")
  219. inputs.files(file("$buildDir/distributions/sonar-application-${version}.zip"))
  220. outputs.upToDateWhen { true }
  221. doLast {
  222. println("delete directory ${unzippedDir}")
  223. project.delete(unzippedDir)
  224. }
  225. }
  226. assemble.dependsOn cleanLocalUnzippedDir
  227. artifacts { zip zip }
  228. artifactoryPublish.skip = false
  229. publishing {
  230. publications {
  231. mavenJava(MavenPublication) {
  232. artifact zip
  233. }
  234. }
  235. }