Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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