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 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. filesMatching('**/bin/elasticsearch-env') {
  97. // to avoid warning logs
  98. filter { line -> line.replaceAll('echo "warning: no-jdk distributions.*', ':') }
  99. }
  100. // elasticsearch script will be replaced by patched version below
  101. exclude '**/bin/elasticsearch'
  102. exclude '**/bin/elasticsearch-cli'
  103. exclude '**/bin/elasticsearch-keystore'
  104. exclude '**/bin/elasticsearch-node'
  105. exclude '**/bin/elasticsearch-shard'
  106. exclude '**/jdk/**'
  107. exclude '**/lib/tools/**'
  108. exclude '**/modules/aggs-matrix-stats/**'
  109. exclude '**/modules/geo/**'
  110. exclude '**/modules/ingest-common/**'
  111. exclude '**/modules/ingest-geoip/**'
  112. exclude '**/modules/ingest-user-agent/**'
  113. exclude '**/modules/kibana/**'
  114. exclude '**/modules/lang-expression/**'
  115. exclude '**/modules/lang-mustache/**'
  116. exclude '**/modules/mapper-extras/**'
  117. exclude '**/modules/rank-eval/**'
  118. exclude '**/modules/reindex/**'
  119. exclude '**/modules/repository-url/**'
  120. exclude '**/modules/tasks/**'
  121. exclude '**/modules/constant-keyword/**'
  122. exclude '**/modules/flattened/**'
  123. exclude '**/modules/frozen-indices/**'
  124. exclude '**/modules/mapper-version/**'
  125. exclude '**/modules/repositories-metering-api/**'
  126. exclude '**/modules/repository-encrypted/**'
  127. exclude '**/modules/search-business-rules/**'
  128. exclude '**/modules/searchable-snapshots/**'
  129. exclude '**/modules/snapshot-repo-test-kit/**'
  130. exclude '**/modules/spatial/**'
  131. exclude '**/modules/transform/**'
  132. exclude '**/modules/unsigned-long/**'
  133. exclude '**/modules/vectors/**'
  134. exclude '**/modules/wildcard/**'
  135. exclude '**/modules/x-pack-*/**'
  136. includeEmptyDirs = false
  137. }
  138. into("${archiveDir}/conf/") {
  139. from file('src/main/assembly/conf/sonar.properties')
  140. filter(ReplaceTokens, tokens: [
  141. 'searchDefaultHeapSize': '512MB',
  142. 'searchJavaOpts' : '-Xmx512m -Xms512m -XX:MaxDirectMemorySize=256m -XX:+HeapDumpOnOutOfMemoryError',
  143. 'ceDefaultHeapSize' : '512MB',
  144. 'ceJavaOpts' : '-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError',
  145. 'webDefaultHeapSize' : '512MB',
  146. 'webJavaOpts' : '-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError'
  147. ])
  148. }
  149. into("${archiveDir}/conf/") {
  150. from file('src/main/assembly/conf/wrapper.conf')
  151. filter(ReplaceTokens, tokens: [
  152. 'sqversion': version
  153. ])
  154. }
  155. into("${archiveDir}/elasticsearch/") {
  156. from file('src/main/assembly/elasticsearch-patch')
  157. include 'bin/elasticsearch'
  158. }
  159. // Create the empty dir (plugins) required by elasticsearch
  160. into("${archiveDir}/elasticsearch/") {
  161. from "$buildDir/elasticsearch"
  162. }
  163. into("${archiveDir}/lib/extensions/") {
  164. from configurations.bundledPlugin
  165. }
  166. into("${archiveDir}/lib/jsw/") {
  167. from configurations.jsw
  168. }
  169. into("${archiveDir}/lib/scanner/") {
  170. from configurations.scanner
  171. }
  172. into("${archiveDir}/lib/") {
  173. from shadowJar
  174. }
  175. into("${archiveDir}/web/") {
  176. duplicatesStrategy DuplicatesStrategy.FAIL
  177. // FIXME use configurations.web with correct artifacts
  178. from(tasks.getByPath(':server:sonar-web:yarn_run').outputs) { a ->
  179. if (official) {
  180. project(':private:branding').fileTree('src').visit { b ->
  181. if (!b.isDirectory()) {
  182. a.exclude b.relativePath.toString()
  183. }
  184. }
  185. }
  186. }
  187. if (official) {
  188. from project(':private:branding').file('src')
  189. }
  190. }
  191. into("${archiveDir}/lib/jdbc/mssql/") {
  192. from configurations.jdbc_mssql
  193. }
  194. into("${archiveDir}/lib/jdbc/postgresql/") {
  195. from configurations.jdbc_postgresql
  196. }
  197. into("${archiveDir}/lib/jdbc/h2/") {
  198. from configurations.jdbc_h2
  199. }
  200. into("${archiveDir}/lib/") {
  201. from configurations.shutdowner
  202. }
  203. }
  204. // Create the empty dir required by elasticsearch
  205. zip.doFirst {
  206. new File(buildDir, 'elasticsearch/plugins').mkdirs()
  207. }
  208. // Check the size of the archive
  209. zip.doLast {
  210. def minLength = 295000000
  211. def maxLength = 310000000
  212. def length = archiveFile.get().asFile.length()
  213. if (length < minLength)
  214. throw new GradleException("$archiveName size ($length) too small. Min is $minLength")
  215. if (length > maxLength)
  216. throw new GradleException("$distsDir/$archiveName size ($length) too large. Max is $maxLength")
  217. }
  218. assemble.dependsOn zip
  219. // the script start.sh unpacks OSS distribution into $buildDir/distributions/sonarqube-oss.
  220. // This directory should be deleted when the zip is changed.
  221. task cleanLocalUnzippedDir(dependsOn: zip) {
  222. def unzippedDir = file("$buildDir/distributions/sonarqube-$version")
  223. inputs.files(file("$buildDir/distributions/sonar-application-${version}.zip"))
  224. outputs.upToDateWhen { true }
  225. doLast {
  226. println("delete directory ${unzippedDir}")
  227. project.delete(unzippedDir)
  228. }
  229. }
  230. assemble.dependsOn cleanLocalUnzippedDir
  231. artifacts { zip zip }
  232. artifactoryPublish.skip = false
  233. publishing {
  234. publications {
  235. mavenJava(MavenPublication) {
  236. artifact zip
  237. }
  238. }
  239. }