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

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