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

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