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

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