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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. import groovy.json.JsonOutput
  2. import org.sonar.build.BlackBoxTest
  3. import static org.gradle.api.JavaVersion.VERSION_17
  4. plugins {
  5. // Ordered alphabetically
  6. id 'com.github.hierynomus.license' version '0.16.1'
  7. id "com.github.hierynomus.license-report" version "0.16.1" apply false
  8. id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
  9. id 'com.google.protobuf' version '0.8.19' apply false
  10. id 'com.jfrog.artifactory' version '4.32.0'
  11. id "de.undercouch.download" version "5.4.0" apply false
  12. id 'io.spring.dependency-management' version '1.1.0'
  13. id "org.cyclonedx.bom" version "1.7.4" apply false
  14. id 'org.sonarqube' version '4.2.1.3168'
  15. }
  16. if (!JavaVersion.current().isCompatibleWith(VERSION_17)) {
  17. throw new GradleException("JDK 17+ is required to perform this build. It's currently " + System.getProperty("java.home") + ".")
  18. }
  19. /**
  20. * The BOM related tasks are disabled by default, activated by:
  21. * - running in the CI and being on a main branch or a nightly build,
  22. * - or using '-Dbom' project property
  23. * - or by explicit call to 'cyclonedxBom' Gradle task
  24. */
  25. def bomTasks = "cyclonedxBom"
  26. def ghBranch = System.getenv()["GITHUB_BRANCH"]
  27. def isMainBranch = ghBranch in ['master'] || ghBranch ==~ 'branch-[\\d.]+'
  28. def isNightlyBuild = ghBranch == "branch-nightly-build"
  29. boolean enableBom = System.getenv('CI') == "true" && (isMainBranch || isNightlyBuild) ||
  30. System.getProperty("bom") != null ||
  31. gradle.startParameter.taskNames.findAll({ it.matches(".*:($bomTasks)") })
  32. allprojects {
  33. apply plugin: 'com.jfrog.artifactory'
  34. apply plugin: 'maven-publish'
  35. ext.versionInSources = version
  36. ext.buildNumber = System.getProperty("buildNumber")
  37. // when no buildNumber is provided, then project version must end with '-SNAPSHOT'
  38. if (ext.buildNumber == null) {
  39. version = "${version}-SNAPSHOT".toString()
  40. ext.versionWithoutBuildNumber = version
  41. } else {
  42. ext.versionWithoutBuildNumber = version
  43. version = (version.toString().count('.') == 1 ? "${version}.0.${ext.buildNumber}" : "${version}.${ext.buildNumber}").toString()
  44. }
  45. task cacheDependencies {
  46. doLast {
  47. configurations.each { conf ->
  48. if (conf.isCanBeResolved()) {
  49. if (conf.getName() != 'appZip')
  50. conf.resolve()
  51. }
  52. }
  53. }
  54. }
  55. ext {
  56. release = project.hasProperty('release') && project.getProperty('release')
  57. official = project.hasProperty('official') && project.getProperty('official')
  58. }
  59. ext.enableBom = enableBom
  60. if (!enableBom) {
  61. tasks.matching { it.name.matches(bomTasks) }.all({
  62. logger.info("{} disabled", it.name);
  63. it.enabled = false
  64. })
  65. }
  66. repositories {
  67. def repository = project.hasProperty('qa') ? 'sonarsource-qa' : 'sonarsource'
  68. // The environment variables ARTIFACTORY_PRIVATE_USERNAME and ARTIFACTORY_PRIVATE_PASSWORD are used on QA env (Jenkins)
  69. // On local box, please add artifactoryUsername and artifactoryPassword to ~/.gradle/gradle.properties
  70. def artifactoryUsername = System.env.'ARTIFACTORY_PRIVATE_USERNAME' ?: (project.hasProperty('artifactoryUsername') ? project.getProperty('artifactoryUsername') : '')
  71. def artifactoryPassword = System.env.'ARTIFACTORY_PRIVATE_PASSWORD' ?: (project.hasProperty('artifactoryPassword') ? project.getProperty('artifactoryPassword') : '')
  72. maven {
  73. if (artifactoryUsername && artifactoryPassword) {
  74. credentials {
  75. username artifactoryUsername
  76. password artifactoryPassword
  77. }
  78. } else {
  79. // Workaround for artifactory
  80. // https://www.jfrog.com/jira/browse/RTFACT-13797
  81. repository = 'public'
  82. }
  83. url "https://repox.jfrog.io/repox/${repository}"
  84. }
  85. ivy {
  86. if (artifactoryUsername && artifactoryPassword) {
  87. credentials {
  88. username artifactoryUsername
  89. password artifactoryPassword
  90. }
  91. url "https://repox.jfrog.io/repox/sonarsource-bucket"
  92. patternLayout {
  93. artifact '/[organisation]/[module]/[module]-[revision].[ext]'
  94. }
  95. } else {
  96. // For public build
  97. url "https://artifacts.elastic.co/downloads/"
  98. patternLayout {
  99. artifact '/[organisation]/[module]-[revision].[ext]'
  100. }
  101. }
  102. metadataSources { artifact() }
  103. }
  104. }
  105. task allDependencies {
  106. dependsOn 'dependencies'
  107. }
  108. artifactory {
  109. clientConfig.setIncludeEnvVars(true)
  110. clientConfig.setEnvVarsExcludePatterns('*pass*,*psw*,*secret*,*MAVEN_CMD_LINE_ARGS*,sun.java.command,*token*,*login*,*key*,*signing*,*auth*,*pwd*')
  111. contextUrl = System.getenv('ARTIFACTORY_URL')
  112. publish {
  113. repository {
  114. repoKey = System.getenv('ARTIFACTORY_DEPLOY_REPO')
  115. username = System.getenv('ARTIFACTORY_DEPLOY_USERNAME') ?: project.properties.artifactoryUsername
  116. password = System.getenv('ARTIFACTORY_DEPLOY_PASSWORD') ?: project.properties.artifactoryPaswword
  117. }
  118. defaults {
  119. properties = [
  120. 'build.name': 'sonar-enterprise',
  121. 'build.number': System.getenv('BUILD_NUMBER'),
  122. 'pr.branch.target': System.getenv('GITHUB_BASE_BRANCH'),
  123. 'pr.number': System.getenv('PULL_REQUEST'),
  124. 'vcs.branch': ghBranch,
  125. 'vcs.revision': System.getenv('GIT_SHA1'),
  126. 'version': version
  127. ]
  128. publications('mavenJava')
  129. publishPom = true
  130. publishIvy = false
  131. }
  132. }
  133. clientConfig.info.setBuildName('sonar-enterprise')
  134. clientConfig.info.setBuildNumber(System.getenv('BUILD_NUMBER'))
  135. // Define the artifacts to be deployed to https://binaries.sonarsource.com on releases
  136. clientConfig.info.addEnvironmentProperty('ARTIFACTS_TO_PUBLISH',
  137. "${project.group}:sonar-application:zip," +
  138. "com.sonarsource.sonarqube:sonarqube-developer:zip," +
  139. "com.sonarsource.sonarqube:sonarqube-datacenter:zip," +
  140. "com.sonarsource.sonarqube:sonarqube-enterprise:zip")
  141. // The name of this variable is important because it's used by the delivery process when extracting version from Artifactory build info.
  142. clientConfig.info.addEnvironmentProperty('PROJECT_VERSION', "${version}")
  143. }
  144. }
  145. apply plugin: 'org.sonarqube'
  146. sonar {
  147. properties {
  148. property 'sonar.projectName', projectTitle
  149. property 'sonar.projectVersion', "${versionInSources}-SNAPSHOT"
  150. property 'sonar.buildString', version
  151. }
  152. }
  153. tasks.named('wrapper') {
  154. distributionType = Wrapper.DistributionType.ALL
  155. }
  156. subprojects {
  157. apply plugin: 'com.github.hierynomus.license'
  158. apply plugin: 'io.spring.dependency-management'
  159. apply plugin: 'jacoco'
  160. apply plugin: 'java-library'
  161. apply plugin: 'idea'
  162. apply plugin: 'signing'
  163. // do not deploy to Artifactory by default
  164. artifactoryPublish.skip = true
  165. compileJava.options.encoding = "UTF-8"
  166. compileTestJava.options.encoding = "UTF-8"
  167. def testFixtureSrc = 'src/testFixtures'
  168. if (file(testFixtureSrc).exists()) {
  169. apply plugin: 'java-test-fixtures'
  170. }
  171. ext {
  172. protobufVersion = '3.22.2'
  173. springVersion = '5.3.28'
  174. }
  175. sonar {
  176. properties {
  177. property 'sonar.moduleKey', project.group + ':' + project.name
  178. }
  179. }
  180. sourceSets {
  181. test {
  182. resources {
  183. srcDirs += ['src/it/resources']
  184. }
  185. java {
  186. srcDirs += ['src/it/java']
  187. }
  188. }
  189. bbt {
  190. resources {
  191. srcDirs = ['src/bbt/resources']
  192. }
  193. java {
  194. srcDirs = ['src/bbt/java']
  195. }
  196. }
  197. }
  198. // Central place for definition dependency versions and exclusions.
  199. dependencyManagement {
  200. dependencies {
  201. // bundled plugin list -- keep it alphabetically ordered
  202. dependency 'com.sonarsource.abap:sonar-abap-plugin:3.12.0.4303'
  203. dependency 'com.sonarsource.cobol:sonar-cobol-plugin:5.3.0.6122'
  204. dependency 'com.sonarsource.cpp:sonar-cfamily-plugin:6.45.0.62016'
  205. dependency 'com.sonarsource.dbd:sonar-dbd-plugin:1.16.0.4300'
  206. dependency 'com.sonarsource.dbd:sonar-dbd-java-frontend-plugin:1.16.0.4300'
  207. dependency 'com.sonarsource.dbd:sonar-dbd-python-frontend-plugin:1.16.0.4300'
  208. dependency 'com.sonarsource.pli:sonar-pli-plugin:1.13.0.3651'
  209. dependency 'com.sonarsource.plsql:sonar-plsql-plugin:3.9.0.5181'
  210. dependency 'com.sonarsource.plugins.vb:sonar-vb-plugin:2.10.0.3598'
  211. dependency 'com.sonarsource.rpg:sonar-rpg-plugin:3.4.0.3394'
  212. dependency 'com.sonarsource.security:sonar-security-csharp-frontend-plugin:10.1.0.21056'
  213. dependency 'com.sonarsource.security:sonar-security-java-frontend-plugin:10.1.0.21056'
  214. dependency 'com.sonarsource.security:sonar-security-php-frontend-plugin:10.1.0.21056'
  215. dependency 'com.sonarsource.security:sonar-security-plugin:10.1.0.21056'
  216. dependency 'com.sonarsource.security:sonar-security-python-frontend-plugin:10.1.0.21056'
  217. dependency 'com.sonarsource.security:sonar-security-js-frontend-plugin:10.1.0.21056'
  218. dependency 'com.sonarsource.slang:sonar-apex-plugin:1.13.0.4374'
  219. dependency 'com.sonarsource.swift:sonar-swift-plugin:4.9.0.5915'
  220. dependency 'com.sonarsource.tsql:sonar-tsql-plugin:1.9.0.5692'
  221. dependency 'org.sonarsource.config:sonar-config-plugin:1.2.0.267'
  222. dependency 'org.sonarsource.dotnet:sonar-csharp-plugin:9.3.0.71466'
  223. dependency 'org.sonarsource.dotnet:sonar-vbnet-plugin:9.3.0.71466'
  224. dependency 'org.sonarsource.flex:sonar-flex-plugin:2.9.0.3375'
  225. dependency 'org.sonarsource.html:sonar-html-plugin:3.8.0.3510'
  226. dependency 'org.sonarsource.jacoco:sonar-jacoco-plugin:1.3.0.1538'
  227. dependency 'org.sonarsource.java:sonar-java-plugin:7.20.0.31692'
  228. dependency 'org.sonarsource.javascript:sonar-javascript-plugin:10.3.1.21905'
  229. dependency 'org.sonarsource.php:sonar-php-plugin:3.30.0.9766'
  230. dependency 'org.sonarsource.plugins.cayc:sonar-cayc-plugin:2.0.0.334'
  231. dependency 'org.sonarsource.python:sonar-python-plugin:4.3.0.11660'
  232. dependency 'org.sonarsource.slang:sonar-go-plugin:1.13.0.4374'
  233. dependency 'org.sonarsource.kotlin:sonar-kotlin-plugin:2.15.0.2579'
  234. dependency 'org.sonarsource.slang:sonar-ruby-plugin:1.13.0.4374'
  235. dependency 'org.sonarsource.slang:sonar-scala-plugin:1.13.0.4374'
  236. dependency "org.sonarsource.api.plugin:sonar-plugin-api:$pluginApiVersion"
  237. dependency "org.sonarsource.api.plugin:sonar-plugin-api-test-fixtures:$pluginApiVersion"
  238. dependency 'org.sonarsource.xml:sonar-xml-plugin:2.8.1.4006'
  239. dependency 'org.sonarsource.iac:sonar-iac-plugin:1.17.0.3976'
  240. dependency 'org.sonarsource.text:sonar-text-plugin:2.1.0.1163'
  241. // please keep this list alphabetically ordered
  242. dependencySet(group: 'ch.qos.logback', version: '1.3.8') {
  243. entry 'logback-access'
  244. entry 'logback-classic'
  245. entry 'logback-core'
  246. }
  247. dependency('commons-beanutils:commons-beanutils:1.9.4') {
  248. exclude 'commons-logging:commons-logging'
  249. }
  250. dependency 'commons-codec:commons-codec:1.15'
  251. dependency 'commons-dbutils:commons-dbutils:1.7'
  252. dependency 'commons-io:commons-io:2.13.0'
  253. dependency 'commons-lang:commons-lang:2.6'
  254. imports { mavenBom 'com.fasterxml.jackson:jackson-bom:2.15.2' }
  255. dependency 'com.eclipsesource.minimal-json:minimal-json:0.9.5'
  256. dependencySet(group: 'com.github.scribejava', version: '8.3.3') {
  257. entry 'scribejava-apis'
  258. entry 'scribejava-core'
  259. }
  260. dependency 'com.github.everit-org.json-schema:org.everit.json.schema:1.14.0'
  261. // This project is no longer maintained and was forked
  262. // by https://github.com/java-diff-utils/java-diff-utils
  263. // (io.github.java-diff-utils:java-diff-utils).
  264. dependency 'com.googlecode.java-diff-utils:diffutils:1.3.0'
  265. dependency('com.googlecode.json-simple:json-simple:1.1.1') {
  266. exclude 'junit:junit'
  267. }
  268. dependency 'io.prometheus:simpleclient:0.16.0'
  269. dependency 'io.prometheus:simpleclient_common:0.16.0'
  270. dependency 'io.prometheus:simpleclient_servlet:0.16.0'
  271. dependency 'com.google.code.findbugs:jsr305:3.0.2'
  272. dependency 'com.google.code.gson:gson:2.10.1'
  273. dependency('com.google.guava:guava:32.0.1-jre') {
  274. exclude 'com.google.errorprone:error_prone_annotations'
  275. exclude 'com.google.guava:listenablefuture'
  276. exclude 'com.google.j2objc:j2objc-annotations'
  277. exclude 'org.checkerframework:checker-qual'
  278. exclude 'org.codehaus.mojo:animal-sniffer-annotations'
  279. }
  280. dependency "com.google.protobuf:protobuf-java:${protobufVersion}"
  281. dependency 'com.h2database:h2:2.1.214'
  282. dependencySet(group: 'com.hazelcast', version: '5.3.1') {
  283. entry 'hazelcast'
  284. }
  285. // Documentation must be updated if mssql-jdbc is updated: https://github.com/SonarSource/sonarqube/commit/03e4773ebf6cba854cdcf57a600095f65f4f53e7
  286. dependency('com.microsoft.sqlserver:mssql-jdbc:12.2.0.jre11') {
  287. exclude 'com.fasterxml.jackson.core:jackson-databind'
  288. }
  289. dependency 'com.onelogin:java-saml:2.9.0'
  290. dependency 'com.oracle.database.jdbc:ojdbc11:23.2.0.0'
  291. dependency 'org.aspectj:aspectjtools:1.9.19'
  292. dependencySet(group: 'com.squareup.okhttp3', version: '4.11.0') {
  293. entry 'okhttp'
  294. entry 'mockwebserver'
  295. entry 'okhttp-tls'
  296. }
  297. dependency 'org.json:json:20230618'
  298. dependency 'com.tngtech.java:junit-dataprovider:1.13.1'
  299. dependencySet(group: 'io.jsonwebtoken', version: '0.11.5') {
  300. entry 'jjwt-api'
  301. entry 'jjwt-impl'
  302. entry 'jjwt-jackson'
  303. }
  304. dependency 'com.auth0:java-jwt:4.4.0'
  305. dependency 'io.netty:netty-all:4.1.93.Final'
  306. dependency 'com.sun.mail:javax.mail:1.6.2'
  307. dependency 'javax.annotation:javax.annotation-api:1.3.2'
  308. dependency 'javax.inject:javax.inject:1'
  309. dependency 'javax.servlet:javax.servlet-api:4.0.1'
  310. dependency 'javax.xml.bind:jaxb-api:2.3.1'
  311. dependency 'junit:junit:4.13.2'
  312. dependency 'org.xmlunit:xmlunit-core:2.9.1'
  313. dependency 'org.xmlunit:xmlunit-matchers:2.9.1'
  314. dependency 'net.jpountz.lz4:lz4:1.3.0'
  315. dependency 'net.lightbody.bmp:littleproxy:1.1.0-beta-bmp-17'
  316. dependency 'org.awaitility:awaitility:4.2.0'
  317. dependency 'org.apache.commons:commons-csv:1.10.0'
  318. dependency 'org.apache.commons:commons-email:1.5'
  319. dependency 'com.zaxxer:HikariCP:5.0.1'
  320. dependency('org.apache.httpcomponents:httpclient:4.5.14') {
  321. exclude 'commons-logging:commons-logging'
  322. }
  323. // Be aware that Log4j is used by Elasticsearch client
  324. dependencySet(group: 'org.apache.logging.log4j', version: '2.20.0') {
  325. entry 'log4j-core'
  326. entry 'log4j-api'
  327. entry 'log4j-to-slf4j'
  328. }
  329. dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.74') {
  330. entry 'tomcat-embed-core'
  331. entry('tomcat-embed-jasper') {
  332. exclude 'org.eclipse.jdt.core.compiler:ecj'
  333. }
  334. }
  335. dependency 'org.assertj:assertj-core:3.24.2'
  336. dependency 'org.assertj:assertj-guava:3.24.2'
  337. dependency('org.codehaus.sonar:sonar-channel:4.2') {
  338. exclude 'org.slf4j:slf4j-api'
  339. }
  340. dependency 'org.codehaus.sonar:sonar-classloader:1.0'
  341. dependency 'com.fasterxml.staxmate:staxmate:2.4.0'
  342. dependencySet(group: 'org.eclipse.jetty', version: '9.4.6.v20170531') {
  343. entry 'jetty-proxy'
  344. entry 'jetty-server'
  345. entry 'jetty-servlet'
  346. }
  347. // "elasticsearchDownloadUrlFile" and "elasticsearchDownloadSha512" must also be updated in gradle.properties
  348. dependency('org.elasticsearch.client:elasticsearch-rest-high-level-client:7.17.10') {
  349. exclude 'org.apache.logging.log4j:log4j-core'
  350. }
  351. dependency 'org.elasticsearch.plugin:transport-netty4-client:7.17.10'
  352. dependency 'org.elasticsearch:mocksocket:1.2'
  353. dependency 'org.codelibs.elasticsearch.module:analysis-common:7.17.9'
  354. dependency 'org.codelibs.elasticsearch.module:reindex:7.17.9'
  355. dependency 'org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r'
  356. dependency 'org.tmatesoft.svnkit:svnkit:1.10.11'
  357. dependency 'org.hamcrest:hamcrest-all:1.3'
  358. dependency 'org.jsoup:jsoup:1.16.1'
  359. dependency 'org.mindrot:jbcrypt:0.4'
  360. dependency('org.mockito:mockito-core:5.4.0') {
  361. exclude 'org.hamcrest:hamcrest-core'
  362. }
  363. dependency "org.springframework:spring-test:${springVersion}"
  364. dependency 'org.mybatis:mybatis:3.5.13'
  365. dependencySet(group: 'org.slf4j', version: '2.0.7') {
  366. entry 'jcl-over-slf4j'
  367. entry 'jul-to-slf4j'
  368. entry 'log4j-over-slf4j'
  369. entry 'slf4j-api'
  370. }
  371. dependency 'org.postgresql:postgresql:42.6.0'
  372. dependency 'org.reflections:reflections:0.10.2'
  373. dependency 'org.simpleframework:simple:5.1.6'
  374. dependency 'org.sonarsource.git.blame:git-files-blame:1.0.2.275'
  375. dependency 'org.sonarsource.orchestrator:sonar-orchestrator:3.42.0.312'
  376. dependency 'org.sonarsource.update-center:sonar-update-center-common:1.30.0.1030'
  377. dependency("org.springframework:spring-context:${springVersion}") {
  378. exclude 'commons-logging:commons-logging'
  379. }
  380. dependency ("org.springframework:spring-webmvc:${springVersion}") {
  381. exclude 'commons-logging:commons-logging'
  382. }
  383. dependency 'org.springdoc:springdoc-openapi-ui:1.7.0'
  384. dependency 'org.subethamail:subethasmtp:3.1.7'
  385. dependency 'org.yaml:snakeyaml:2.0'
  386. // please keep this list alphabetically ordered
  387. }
  388. }
  389. configurations {
  390. bbtCompile.extendsFrom testCompile
  391. bbtRuntime.extendsFrom testRuntime
  392. bbtImplementation.extendsFrom testImplementation
  393. // global exclusions
  394. all {
  395. // do not conflict with com.sun.mail:javax.mail
  396. exclude group: 'javax.mail', module: 'mail'
  397. }
  398. }
  399. tasks.withType(Javadoc) {
  400. options.addStringOption('Xdoclint:none', '-quiet')
  401. options.encoding = 'UTF-8'
  402. title = project.name + ' ' + versionWithoutBuildNumber
  403. }
  404. task sourcesJar(type: Jar, dependsOn: classes) {
  405. archiveClassifier = 'sources'
  406. from sourceSets.main.allSource
  407. }
  408. task javadocJar(type: Jar, dependsOn: javadoc) {
  409. archiveClassifier = 'javadoc'
  410. from javadoc.destinationDir
  411. }
  412. // generate code before opening project in IDE (Eclipse or Intellij)
  413. task ide() {
  414. // empty by default. Dependencies are added to the task
  415. // when needed (see protobuf modules for example)
  416. }
  417. jacocoTestReport {
  418. reports {
  419. xml.required = true
  420. csv.required = false
  421. html.required = false
  422. }
  423. }
  424. normalization {
  425. runtimeClasspath {
  426. // Following classpath resources contain volatile data that changes in each CI build (build number, commit id, time),
  427. // so we exclude them from calculation of build cache key of test tasks:
  428. ignore 'META-INF/MANIFEST.MF'
  429. ignore 'sonar-api-version.txt'
  430. ignore 'sq-version.txt'
  431. }
  432. }
  433. ext.failedTests = []
  434. test {
  435. jvmArgs '-Dfile.encoding=UTF8'
  436. maxHeapSize = '1G'
  437. systemProperty 'java.awt.headless', true
  438. testLogging {
  439. events "skipped", "failed" // verbose log for failed and skipped tests (by default the name of the tests are not logged)
  440. exceptionFormat 'full' // log the full stack trace (default is the 1st line of the stack trace)
  441. }
  442. jacoco {
  443. enabled = true // do not disable recording of code coverage, so that remote Gradle cache entry can be used locally
  444. includes = ['com.sonar.*', 'com.sonarsource.*', 'org.sonar.*', 'org.sonarqube.*', 'org.sonarsource.*']
  445. }
  446. if (project.hasProperty('maxParallelTests')) {
  447. maxParallelForks = project.maxParallelTests as int
  448. }
  449. if (project.hasProperty('parallelTests')) {
  450. // See https://guides.gradle.org/performance/#parallel_test_execution
  451. maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
  452. }
  453. afterTest { descriptor, result ->
  454. if (result.resultType == TestResult.ResultType.FAILURE) {
  455. String failedTest = " ${descriptor.className} > ${descriptor.name}"
  456. failedTests << failedTest
  457. }
  458. }
  459. }
  460. gradle.buildFinished {
  461. if (!failedTests.empty) {
  462. println "\nFailed tests:"
  463. failedTests.each { failedTest ->
  464. println failedTest
  465. }
  466. println ""
  467. }
  468. }
  469. def protoMainSrc = 'src/main/protobuf'
  470. def protoTestSrc = 'src/test/protobuf'
  471. if (file(protoMainSrc).exists() || file(protoTestSrc).exists()) {
  472. // protobuf must be applied after java
  473. apply plugin: 'com.google.protobuf'
  474. sourceSets.main.proto.srcDir protoMainSrc // in addition to the default 'src/main/proto'
  475. sourceSets.test.proto.srcDir protoTestSrc // in addition to the default 'src/test/proto'
  476. protobuf {
  477. protoc {
  478. artifact = "com.google.protobuf:protoc:${protobufVersion}"
  479. }
  480. }
  481. jar {
  482. exclude('**/*.proto')
  483. }
  484. idea {
  485. module {
  486. sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java")
  487. testSourceDirs += file("${protobuf.generatedFilesBaseDir}/test/java")
  488. generatedSourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java")
  489. generatedSourceDirs += file("${protobuf.generatedFilesBaseDir}/test/java")
  490. }
  491. }
  492. ide.dependsOn(['generateProto', 'generateTestProto'])
  493. }
  494. if (official) {
  495. jar {
  496. // do not break incremental build on non official versions
  497. manifest {
  498. attributes(
  499. 'Version': "${version}",
  500. 'Implementation-Build': System.getenv('GIT_SHA1'),
  501. 'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
  502. )
  503. }
  504. }
  505. }
  506. license {
  507. header = rootProject.file('HEADER')
  508. strictCheck true
  509. encoding = 'UTF-8'
  510. mapping {
  511. java = 'SLASHSTAR_STYLE'
  512. js = 'SLASHSTAR_STYLE'
  513. ts = 'SLASHSTAR_STYLE'
  514. tsx = 'SLASHSTAR_STYLE'
  515. css = 'SLASHSTAR_STYLE'
  516. }
  517. includes(['**/*.java', '**/*.js', '**/*.ts', '**/*.tsx', '**/*.css'])
  518. }
  519. tasks.withType(GenerateModuleMetadata) {
  520. enabled = false
  521. }
  522. publishing {
  523. publications {
  524. mavenJava(MavenPublication) {
  525. pom {
  526. name = 'SonarQube'
  527. description = project.description
  528. url = 'http://www.sonarqube.org/'
  529. organization {
  530. name = 'SonarSource'
  531. url = 'http://www.sonarsource.com'
  532. }
  533. licenses {
  534. license {
  535. name = 'GNU LGPL 3'
  536. url = 'http://www.gnu.org/licenses/lgpl.txt'
  537. distribution = 'repo'
  538. }
  539. }
  540. scm {
  541. url = 'https://github.com/SonarSource/sonarqube'
  542. }
  543. developers {
  544. developer {
  545. id = 'sonarsource-team'
  546. name = 'SonarSource Team'
  547. }
  548. }
  549. }
  550. }
  551. }
  552. }
  553. tasks.withType(Test) {
  554. configurations {
  555. utMonitoring
  556. }
  557. dependencies {
  558. testImplementation project(":ut-monitoring")
  559. utMonitoring 'org.aspectj:aspectjweaver:1.9.19'
  560. }
  561. }
  562. tasks.withType(BlackBoxTest) {
  563. jacoco.enabled = false
  564. testClassesDirs = sourceSets.bbt.output.classesDirs
  565. classpath = sourceSets.bbt.runtimeClasspath
  566. configurations {
  567. includeInTestResources
  568. }
  569. dependencies {
  570. bbtRuntimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
  571. bbtRuntimeOnly 'com.oracle.database.jdbc:ojdbc11'
  572. bbtRuntimeOnly 'org.postgresql:postgresql'
  573. bbtRuntimeOnly project(':plugins:sonar-xoo-plugin')
  574. bbtImplementation 'org.sonarsource.orchestrator:sonar-orchestrator'
  575. bbtImplementation project(":sonar-testing-harness")
  576. bbtImplementation project(":private:it-common")
  577. }
  578. }
  579. if (isNightlyBuild) {
  580. tasks.withType(Test) {
  581. doFirst {
  582. ext {
  583. aspectJWeaver = configurations.utMonitoring.resolvedConfiguration.resolvedArtifacts.find { it.name == 'aspectjweaver' }
  584. }
  585. jvmArgs "-javaagent:${aspectJWeaver.file}"
  586. }
  587. }
  588. }
  589. signing {
  590. def signingKeyId = findProperty("signingKeyId")
  591. def signingKey = findProperty("signingKey")
  592. def signingPassword = findProperty("signingPassword")
  593. useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
  594. required {
  595. return isMainBranch && gradle.taskGraph.hasTask(":artifactoryPublish")
  596. }
  597. sign publishing.publications
  598. }
  599. tasks.withType(Sign) {
  600. onlyIf {
  601. return !artifactoryPublish.skip && isMainBranch && gradle.taskGraph.hasTask(":artifactoryPublish")
  602. }
  603. }
  604. }
  605. gradle.projectsEvaluated { gradle ->
  606. // yarn_run tasks can't all run in parallel without random issues
  607. // this script ensure all yarn_run tasks run sequentially
  608. def yarnRunTasks = allprojects.findResults { it -> it.tasks.findByName('yarn_run') }
  609. yarnRunTasks.drop(1).eachWithIndex { it, i -> it.mustRunAfter(yarnRunTasks[0..i]) }
  610. }
  611. ext.osAdaptiveCommand = { commands ->
  612. def newCommands = []
  613. if (System.properties['os.name'].toLowerCase().contains('windows')) {
  614. newCommands = ['cmd', '/c']
  615. }
  616. newCommands.addAll(commands)
  617. return newCommands
  618. }
  619. tasks.named('sonarqube') {
  620. long taskStart
  621. doFirst {
  622. taskStart = System.currentTimeMillis()
  623. }
  624. doLast {
  625. long taskDuration = System.currentTimeMillis() - taskStart
  626. File outputFile = new File("/tmp/analysis-monitoring.log")
  627. outputFile.append(JsonOutput.toJson([category: "Analysis", suite: "Standalone", operation: "total", duration: taskDuration]) + '\n')
  628. }
  629. }