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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. //verify if sonar.properties files does not have any external input
  66. task verifySonarProperties(type: Verify) {
  67. def propertiesFile = file('src/main/assembly/conf/sonar.properties')
  68. propertiesFile.withReader { reader ->
  69. def line
  70. while ((line = reader.readLine()) != null) {
  71. if (!line.startsWith('#') && !line.isEmpty()) {
  72. throw new GradleException('sonar.properties file by default must not provide any user configuration.')
  73. }
  74. }
  75. }
  76. }
  77. task verifyElasticSearchDownload(type: Verify) {
  78. src new File(buildDir, "$elasticsearchDownloadUrlFile")
  79. algorithm 'SHA-512'
  80. checksum elasticsearchDownloadSha512
  81. }
  82. task downloadElasticSearch(type: Download) {
  83. def artifactoryUsername = System.env.'ARTIFACTORY_PRIVATE_USERNAME' ?: (project.hasProperty('artifactoryUsername') ? project.getProperty('artifactoryUsername') : '')
  84. def artifactoryPassword = System.env.'ARTIFACTORY_PRIVATE_PASSWORD' ?: (project.hasProperty('artifactoryPassword') ? project.getProperty('artifactoryPassword') : '')
  85. if (artifactoryUsername && artifactoryPassword) {
  86. src "$elasticsearchDownloadRepoxUrlPath$elasticsearchDownloadUrlFile"
  87. username artifactoryUsername
  88. password artifactoryPassword
  89. } else {
  90. src "$elasticsearchDownloadUrlPath$elasticsearchDownloadUrlFile"
  91. }
  92. dest "$buildDir/$elasticsearchDownloadUrlFile"
  93. onlyIfModified true
  94. finalizedBy verifyElasticSearchDownload
  95. }
  96. downloadLicenses {
  97. dependencyConfiguration = 'appLicenses'
  98. }
  99. task zip(type: Zip, dependsOn: [configurations.compileClasspath, tasks.downloadLicenses, downloadElasticSearch, verifyElasticSearchDownload]) {
  100. duplicatesStrategy DuplicatesStrategy.EXCLUDE
  101. def archiveDir = "sonarqube-$project.version"
  102. into("${archiveDir}/") {
  103. from(tasks.downloadLicenses.outputs) {
  104. include 'dependency-license.json'
  105. eachFile { jsonFile ->
  106. def json = new JsonSlurper().parse(jsonFile.file)
  107. json.dependencies.each { dependency ->
  108. if (dependency.licenses.size() > 1) {
  109. def idx = dependency.licenses.findIndexOf { it.name == "Elastic License 2.0" }
  110. if (idx >= 0) {
  111. dependency.licenses = [dependency.licenses[idx]]
  112. }
  113. }
  114. }
  115. json.dependencies.sort { it.name }
  116. def jsonText = JsonOutput.toJson(json)
  117. jsonFile.file.text = JsonOutput.prettyPrint(jsonText)
  118. }
  119. }
  120. from(file('src/main/assembly')) {
  121. exclude 'conf/sonar.properties'
  122. exclude 'conf/wrapper.conf'
  123. exclude 'elasticsearch-patch'
  124. }
  125. }
  126. from(tarTree(downloadElasticSearch.dest)) {
  127. eachFile { fcd ->
  128. def path = fcd.relativePath.segments - fcd.relativeSourcePath.segments + fcd.relativeSourcePath.segments.drop(1)
  129. fcd.relativePath = new RelativePath(true, *path)
  130. }
  131. into("${archiveDir}/elasticsearch")
  132. filesMatching('**/bin/elasticsearch-env') {
  133. // to avoid warning logs
  134. filter { line -> line.replaceAll('echo "warning: no-jdk distributions.*', ':') }
  135. }
  136. // elasticsearch script will be replaced by patched version below
  137. exclude '**/bin/elasticsearch'
  138. exclude '**/bin/elasticsearch-certgen'
  139. exclude '**/bin/elasticsearch-certutil'
  140. exclude '**/bin/elasticsearch-cli'
  141. exclude '**/bin/elasticsearch-croneval'
  142. exclude '**/bin/elasticsearch-geoip'
  143. exclude '**/bin/elasticsearch-keystore'
  144. exclude '**/bin/elasticsearch-migrate'
  145. exclude '**/bin/elasticsearch-node'
  146. exclude '**/bin/elasticsearch-plugin'
  147. exclude '**/bin/elasticsearch-saml-metadata'
  148. exclude '**/bin/elasticsearch-service-tokens'
  149. exclude '**/bin/elasticsearch-setup-passwords'
  150. exclude '**/bin/elasticsearch-shard'
  151. exclude '**/bin/elasticsearch-sql-cli*'
  152. exclude '**/bin/elasticsearch-syskeygen'
  153. exclude '**/bin/elasticsearch-users'
  154. exclude '**/bin/x-pack-env'
  155. exclude '**/bin/x-pack-security-env'
  156. exclude '**/bin/x-pack-watcher-env'
  157. exclude '**/jdk/**'
  158. exclude '**/lib/tools/**'
  159. exclude '**/modules/aggs-matrix-stats/**'
  160. exclude '**/modules/constant-keyword/**'
  161. exclude '**/modules/frozen-indices/**'
  162. exclude '**/modules/ingest-common/**'
  163. exclude '**/modules/ingest-geoip/**'
  164. exclude '**/modules/ingest-user-agent/**'
  165. exclude '**/modules/kibana/**'
  166. exclude '**/modules/lang-expression/**'
  167. exclude '**/modules/lang-mustache/**'
  168. exclude '**/modules/legacy-geo/**'
  169. exclude '**/modules/mapper-extras/**'
  170. exclude '**/modules/mapper-version/**'
  171. exclude '**/modules/percolator/**'
  172. exclude '**/modules/rank-eval/**'
  173. exclude '**/modules/reindex/**'
  174. exclude '**/modules/repositories-metering-api/**'
  175. exclude '**/modules/repository-encrypted/**'
  176. exclude '**/modules/repository-url/**'
  177. exclude '**/modules/runtime-fields-common/**'
  178. exclude '**/modules/search-business-rules/**'
  179. exclude '**/modules/searchable-snapshots/**'
  180. exclude '**/modules/snapshot-repo-test-kit/**'
  181. exclude '**/modules/spatial/**'
  182. exclude '**/modules/transform/**'
  183. exclude '**/modules/unsigned-long/**'
  184. exclude '**/modules/vector-tile/**'
  185. exclude '**/modules/vectors/**'
  186. exclude '**/modules/wildcard/**'
  187. exclude '**/modules/x-pack-*/**'
  188. includeEmptyDirs = false
  189. }
  190. into("${archiveDir}/conf/") {
  191. from file('src/main/assembly/conf/sonar.properties')
  192. filter(ReplaceTokens, tokens: [
  193. 'searchDefaultHeapSize': '512MB',
  194. 'searchJavaOpts' : '-Xmx512m -Xms512m -XX:MaxDirectMemorySize=256m -XX:+HeapDumpOnOutOfMemoryError',
  195. 'ceDefaultHeapSize' : '512MB',
  196. 'ceJavaOpts' : '-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError',
  197. 'webDefaultHeapSize' : '512MB',
  198. 'webJavaOpts' : '-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError'
  199. ])
  200. }
  201. into("${archiveDir}/conf/") {
  202. from file('src/main/assembly/conf/wrapper.conf')
  203. filter(ReplaceTokens, tokens: [
  204. 'sqversion': version
  205. ])
  206. }
  207. into("${archiveDir}/elasticsearch/") {
  208. from file('src/main/assembly/elasticsearch-patch')
  209. include 'bin/elasticsearch'
  210. }
  211. // Create the empty dir (plugins) required by elasticsearch
  212. into("${archiveDir}/elasticsearch/") {
  213. from "$buildDir/elasticsearch"
  214. }
  215. into("${archiveDir}/lib/extensions/") {
  216. from configurations.bundledPlugin
  217. }
  218. into("${archiveDir}/lib/jsw/") {
  219. from configurations.jsw
  220. }
  221. into("${archiveDir}/lib/scanner/") {
  222. from configurations.scanner
  223. }
  224. into("${archiveDir}/lib/") {
  225. from shadowJar
  226. }
  227. into("${archiveDir}/web/") {
  228. duplicatesStrategy DuplicatesStrategy.FAIL
  229. // FIXME use configurations.web with correct artifacts
  230. from(tasks.getByPath(':server:sonar-web:yarn_run').outputs) { a ->
  231. if (official) {
  232. project(':private:branding').fileTree('src').visit { b ->
  233. if (!b.isDirectory()) {
  234. a.exclude b.relativePath.toString()
  235. }
  236. }
  237. }
  238. }
  239. if (official) {
  240. from project(':private:branding').file('src')
  241. }
  242. }
  243. into("${archiveDir}/lib/jdbc/mssql/") {
  244. from configurations.jdbc_mssql
  245. }
  246. into("${archiveDir}/lib/jdbc/postgresql/") {
  247. from configurations.jdbc_postgresql
  248. }
  249. into("${archiveDir}/lib/jdbc/h2/") {
  250. from configurations.jdbc_h2
  251. }
  252. into("${archiveDir}/lib/") {
  253. from configurations.shutdowner
  254. }
  255. }
  256. // Create the empty dir required by elasticsearch
  257. zip.doFirst {
  258. new File(buildDir, 'elasticsearch/plugins').mkdirs()
  259. }
  260. // Check the size of the archive
  261. zip.doLast {
  262. def minLength = 270000000
  263. def maxLength = 285000000
  264. def length = archiveFile.get().asFile.length()
  265. if (length < minLength)
  266. throw new GradleException("${archiveFileName.get()} size ($length) too small. Min is $minLength")
  267. if (length > maxLength)
  268. throw new GradleException("${destinationDirectory.get()}/${archiveFileName.get()} size ($length) too large. Max is $maxLength")
  269. }
  270. assemble.dependsOn zip
  271. // the script start.sh unpacks OSS distribution into $buildDir/distributions/sonarqube-oss.
  272. // This directory should be deleted when the zip is changed.
  273. task cleanLocalUnzippedDir(dependsOn: zip) {
  274. def unzippedDir = file("$buildDir/distributions/sonarqube-$version")
  275. inputs.files(file("$buildDir/distributions/sonar-application-${version}.zip"))
  276. outputs.upToDateWhen { true }
  277. doLast {
  278. println("delete directory ${unzippedDir}")
  279. project.delete(unzippedDir)
  280. }
  281. }
  282. assemble.dependsOn cleanLocalUnzippedDir
  283. artifacts { zip zip }
  284. artifactoryPublish.skip = false
  285. publishing {
  286. publications {
  287. mavenJava(MavenPublication) {
  288. artifact zip
  289. }
  290. }
  291. }