Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. import org.apache.tools.ant.filters.ReplaceTokens
  2. import org.sonar.build.LicenseReader
  3. plugins {
  4. id "com.github.hierynomus.license-report"
  5. id "com.github.johnrengelman.shadow"
  6. id "de.undercouch.download"
  7. id "org.cyclonedx.bom"
  8. }
  9. sonar {
  10. properties {
  11. property 'sonar.projectName', "${projectTitle} :: Application"
  12. }
  13. }
  14. configurations {
  15. zipDist
  16. zip
  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. bundledPlugin_deps {
  33. extendsFrom bundledPlugin
  34. transitive = true
  35. }
  36. appLicenses.extendsFrom(api, web, scanner, jdbc_mssql, jdbc_postgresql, jdbc_h2, bundledPlugin_deps)
  37. cyclonedx
  38. }
  39. jar.enabled = false
  40. shadowJar {
  41. archiveBaseName = 'sonar-application'
  42. archiveClassifier = null
  43. mergeServiceFiles()
  44. manifest {
  45. attributes('Main-Class': 'org.sonar.application.App')
  46. }
  47. }
  48. dependencies {
  49. // please keep list ordered
  50. api 'org.slf4j:slf4j-api'
  51. api 'org.elasticsearch.client:elasticsearch-rest-high-level-client'
  52. api 'org.sonarsource.api.plugin:sonar-plugin-api'
  53. api project(':server:sonar-ce')
  54. api project(':server:sonar-main')
  55. api project(':server:sonar-process')
  56. api project(':server:sonar-webserver')
  57. api project(':sonar-core')
  58. api project(':sonar-plugin-api-impl')
  59. compileOnlyApi 'com.google.code.findbugs:jsr305'
  60. scanner project(path: ':sonar-scanner-engine-shaded', configuration: 'shadow')
  61. cyclonedx project(path: ':sonar-scanner-engine-shaded')
  62. web project(':server:sonar-web')
  63. shutdowner project(':sonar-shutdowner')
  64. jdbc_h2 'com.h2database:h2'
  65. jdbc_mssql 'com.microsoft.sqlserver:mssql-jdbc'
  66. jdbc_postgresql 'org.postgresql:postgresql'
  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. zipDist "sonarqube:elasticsearch:${elasticsearchVersion}-no-jdk-linux-x86_64@tar.gz"
  71. } else {
  72. zipDist "elasticsearch:elasticsearch:${elasticsearchVersion}-linux-x86_64@tar.gz"
  73. }
  74. }
  75. // declare dependencies in configuration bundledPlugin to be packaged in lib/extensions
  76. apply from: 'bundled_plugins.gradle'
  77. //verify if sonar.properties files does not have any external input
  78. task verifySonarProperties(type: Verify) {
  79. def propertiesFile = file('src/main/assembly/conf/sonar.properties')
  80. propertiesFile.withReader { reader ->
  81. def line
  82. while ((line = reader.readLine()) != null) {
  83. if (!line.startsWith('#') && !line.isEmpty()) {
  84. throw new GradleException('sonar.properties file by default must not provide any user configuration.')
  85. }
  86. }
  87. }
  88. }
  89. downloadLicenses {
  90. dependencyConfiguration = 'appLicenses'
  91. }
  92. task zip(type: Zip, dependsOn: [configurations.compileClasspath]) {
  93. duplicatesStrategy DuplicatesStrategy.EXCLUDE
  94. def archiveDir = "sonarqube-$project.version"
  95. if(release) {
  96. dependsOn tasks.downloadLicenses
  97. into("${archiveDir}/") {
  98. from(tasks.downloadLicenses.outputs) {
  99. include 'dependency-license.json'
  100. filter(LicenseReader)
  101. }
  102. }
  103. }
  104. into("${archiveDir}/") {
  105. from(file('src/main/assembly')) {
  106. exclude 'conf/sonar.properties'
  107. exclude 'bin/windows-x86-64/lib/SonarServiceWrapperTemplate.xml'
  108. exclude 'bin/windows-x86-64/StartSonar.bat'
  109. exclude 'bin/linux-x86-64/sonar.sh'
  110. exclude 'bin/macosx-universal-64/sonar.sh'
  111. }
  112. }
  113. ResolvedArtifact elasticSearchArtifact = configurations.zipDist.resolvedConfiguration.resolvedArtifacts.find {
  114. it.moduleVersion.id.name == "elasticsearch"
  115. }
  116. from(tarTree(elasticSearchArtifact.file)) {
  117. eachFile { fcd ->
  118. def path = fcd.relativePath.segments - fcd.relativeSourcePath.segments + fcd.relativeSourcePath.segments.drop(1)
  119. fcd.relativePath = new RelativePath(true, *path)
  120. }
  121. into("${archiveDir}/elasticsearch")
  122. exclude '**/bin/elasticsearch-certgen'
  123. exclude '**/bin/elasticsearch-certutil'
  124. exclude '**/bin/elasticsearch-create-enrollment-token'
  125. exclude '**/bin/elasticsearch-croneval'
  126. exclude '**/bin/elasticsearch-env-from-file'
  127. exclude '**/bin/elasticsearch-geoip'
  128. exclude '**/bin/elasticsearch-keystore'
  129. exclude '**/bin/elasticsearch-node'
  130. exclude '**/bin/elasticsearch-plugin'
  131. exclude '**/bin/elasticsearch-reconfigure-node'
  132. exclude '**/bin/elasticsearch-reset-password'
  133. exclude '**/bin/elasticsearch-saml-metadata'
  134. exclude '**/bin/elasticsearch-service-tokens'
  135. exclude '**/bin/elasticsearch-setup-passwords'
  136. exclude '**/bin/elasticsearch-shard'
  137. exclude '**/bin/elasticsearch-sql-cli'
  138. exclude '**/bin/elasticsearch-sql-cli-8.6.1.jar'
  139. exclude '**/bin/elasticsearch-syskeygen'
  140. exclude '**/bin/elasticsearch-users'
  141. exclude '**/jdk/**'
  142. exclude '**/lib/tools/plugin-cli'
  143. exclude '**/lib/tools/geoip-cli'
  144. exclude '**/lib/tools/ansi-console'
  145. exclude '**/modules/aggs-matrix-stats/**'
  146. exclude '**/modules/constant-keyword/**'
  147. exclude '**/modules/data-streams/**'
  148. exclude '**/modules/frozen-indices/**'
  149. exclude '**/modules/ingest-attachment/**'
  150. exclude '**/modules/ingest-common/**'
  151. exclude '**/modules/ingest-geoip/**'
  152. exclude '**/modules/ingest-user-agent/**'
  153. exclude '**/modules/kibana/**'
  154. exclude '**/modules/lang-expression/**'
  155. exclude '**/modules/lang-mustache/**'
  156. exclude '**/modules/legacy-geo/**'
  157. exclude '**/modules/mapper-extras/**'
  158. exclude '**/modules/mapper-version/**'
  159. exclude '**/modules/percolator/**'
  160. exclude '**/modules/rank-eval/**'
  161. exclude '**/modules/repositories-metering-api/**'
  162. exclude '**/modules/repository-azure/**'
  163. exclude '**/modules/repository-encrypted/**'
  164. exclude '**/modules/repository-gcs/**'
  165. exclude '**/modules/repository-s3/**'
  166. exclude '**/modules/repository-url/**'
  167. exclude '**/modules/runtime-fields-common/**'
  168. exclude '**/modules/search-business-rules/**'
  169. exclude '**/modules/searchable-snapshots/**'
  170. exclude '**/modules/snapshot-based-recoveries/**'
  171. exclude '**/modules/snapshot-repo-test-kit/**'
  172. exclude '**/modules/spatial/**'
  173. exclude '**/modules/transform/**'
  174. exclude '**/modules/unsigned-long/**'
  175. exclude '**/modules/vector-tile/**'
  176. exclude '**/modules/vectors/**'
  177. exclude '**/modules/wildcard/**'
  178. exclude '**/modules/x-pack-aggregate-metric'
  179. exclude '**/modules/x-pack-analytics/**'
  180. exclude '**/modules/x-pack-async/**'
  181. exclude '**/modules/x-pack-async-search/**'
  182. exclude '**/modules/x-pack-autoscaling/**'
  183. exclude '**/modules/x-pack-ccr/**'
  184. exclude '**/modules/x-pack-deprecation/**'
  185. exclude '**/modules/x-pack-enrich/**'
  186. exclude '**/modules/x-pack-eql/**'
  187. exclude '**/modules/x-pack-fleet/**'
  188. exclude '**/modules/x-pack-graph/**'
  189. exclude '**/modules/x-pack-identity-provider/**'
  190. exclude '**/modules/x-pack-ilm/**'
  191. exclude '**/modules/x-pack-logstash/**'
  192. exclude '**/modules/x-pack-monitoring/**'
  193. exclude '**/modules/x-pack-ql/**'
  194. exclude '**/modules/x-pack-rollup/**'
  195. exclude '**/modules/x-pack-ml/**'
  196. exclude '**/modules/x-pack-shutdown/**'
  197. exclude '**/modules/x-pack-sql/**'
  198. exclude '**/modules/x-pack-stack/**'
  199. exclude '**/modules/x-pack-text-structure/**'
  200. exclude '**/modules/x-pack-voting-only-node/**'
  201. exclude '**/modules/x-pack-watcher/**'
  202. exclude '**/modules/x-pack-write-load-forecaster/**'
  203. includeEmptyDirs = false
  204. }
  205. into("${archiveDir}/conf/") {
  206. from file('src/main/assembly/conf/sonar.properties')
  207. filter(ReplaceTokens, tokens: [
  208. 'searchDefaultHeapSize': '512MB',
  209. 'searchJavaOpts' : '-Xmx512m -Xms512m -XX:MaxDirectMemorySize=256m -XX:+HeapDumpOnOutOfMemoryError',
  210. 'ceDefaultHeapSize' : '512MB',
  211. 'ceJavaOpts' : '-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError',
  212. 'webDefaultHeapSize' : '512MB',
  213. 'webJavaOpts' : '-Xmx512m -Xms128m -XX:+HeapDumpOnOutOfMemoryError'
  214. ])
  215. }
  216. into("${archiveDir}/bin/linux-x86-64/") {
  217. from file('src/main/assembly/bin/linux-x86-64/sonar.sh')
  218. filter(ReplaceTokens, tokens: [
  219. 'sqversion': version
  220. ])
  221. }
  222. into("${archiveDir}/bin/macosx-universal-64/") {
  223. from file('src/main/assembly/bin/macosx-universal-64/sonar.sh')
  224. filter(ReplaceTokens, tokens: [
  225. 'sqversion': version
  226. ])
  227. }
  228. into("${archiveDir}/bin/windows-x86-64/") {
  229. from file('src/main/assembly/bin/windows-x86-64/StartSonar.bat')
  230. filter(ReplaceTokens, tokens: [
  231. 'sqversion': version
  232. ])
  233. }
  234. into("${archiveDir}/bin/windows-x86-64/lib/") {
  235. from file('src/main/assembly/bin/windows-x86-64/lib/SonarServiceWrapperTemplate.xml')
  236. filter(ReplaceTokens, tokens: [
  237. 'sqversion': version
  238. ])
  239. }
  240. // Create the empty dir (plugins) required by elasticsearch
  241. into("${archiveDir}/elasticsearch/") {
  242. // Create the empty dir required by elasticsearch
  243. from {
  244. new File(buildDir, 'elasticsearch/plugins').mkdirs()
  245. "$buildDir/elasticsearch"
  246. }
  247. }
  248. into("${archiveDir}/lib/extensions/") {
  249. from configurations.bundledPlugin
  250. }
  251. into("${archiveDir}/lib/scanner/") {
  252. from configurations.scanner
  253. }
  254. into("${archiveDir}/lib/") {
  255. from shadowJar
  256. }
  257. into("${archiveDir}/web/") {
  258. duplicatesStrategy DuplicatesStrategy.FAIL
  259. // FIXME use configurations.web with correct artifacts
  260. from(tasks.getByPath(':server:sonar-web:yarn_run').outputs) { a ->
  261. if (official) {
  262. project(':private:branding').fileTree('src').visit { b ->
  263. if (!b.isDirectory()) {
  264. a.exclude b.relativePath.toString()
  265. }
  266. }
  267. }
  268. }
  269. if (official) {
  270. from project(':private:branding').file('src')
  271. }
  272. }
  273. into("${archiveDir}/lib/jdbc/mssql/") {
  274. from configurations.jdbc_mssql
  275. }
  276. into("${archiveDir}/lib/jdbc/postgresql/") {
  277. from configurations.jdbc_postgresql
  278. }
  279. into("${archiveDir}/lib/jdbc/h2/") {
  280. from configurations.jdbc_h2
  281. }
  282. into("${archiveDir}/lib/") {
  283. from configurations.shutdowner
  284. }
  285. }
  286. // Check the size of the archive
  287. zip.doLast {
  288. def minLength = 340000000
  289. def maxLength = 371000000
  290. def length = archiveFile.get().asFile.length()
  291. if (length < minLength)
  292. throw new GradleException("${archiveFileName.get()} size ($length) too small. Min is $minLength")
  293. if (length > maxLength)
  294. throw new GradleException("${destinationDirectory.get()}/${archiveFileName.get()} size ($length) too large. Max is $maxLength")
  295. }
  296. assemble.dependsOn zip
  297. // the script start.sh unpacks OSS distribution into $buildDir/distributions/sonarqube-oss.
  298. // This directory should be deleted when the zip is changed.
  299. task cleanLocalUnzippedDir(dependsOn: zip) {
  300. def unzippedDir = file("$buildDir/distributions/sonarqube-$version")
  301. inputs.files(file("$buildDir/distributions/sonar-application-${version}.zip"))
  302. outputs.upToDateWhen { true }
  303. doLast {
  304. println("delete directory ${unzippedDir}")
  305. project.delete(unzippedDir)
  306. }
  307. }
  308. assemble.dependsOn cleanLocalUnzippedDir
  309. artifacts { zip zip }
  310. artifactoryPublish.skip = false
  311. def bomFile = layout.buildDirectory.file('reports/bom.json')
  312. cyclonedxBom {
  313. includeConfigs = ["runtimeClasspath", "web", "shutdowner", "jdbc_mssql", "jdbc_postgresql", "jdbc_h2", "bundledPlugin_deps",
  314. "cyclonedx"]
  315. outputs.file bomFile
  316. }
  317. tasks.cyclonedxBom {
  318. inputs.files(configurations.runtimeClasspath, configurations.shutdowner, configurations.jdbc_mssql,
  319. configurations.jdbc_postgresql, configurations.jdbc_h2, configurations.bundledPlugin_deps, configurations.cyclonedx)
  320. }
  321. def bomArtifact = artifacts.add('archives', bomFile.get().asFile) {
  322. type 'json'
  323. classifier 'cyclonedx'
  324. builtBy 'cyclonedxBom'
  325. }
  326. publishing {
  327. publications {
  328. mavenJava(MavenPublication) {
  329. artifact zip
  330. }
  331. if (enableBom) {
  332. mavenJava(MavenPublication) {
  333. artifact bomArtifact
  334. }
  335. }
  336. }
  337. }