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

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