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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  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.13.0.4389'
  203. dependency 'com.sonarsource.cobol:sonar-cobol-plugin:5.4.0.6318'
  204. dependency 'com.sonarsource.cpp:sonar-cfamily-plugin:6.48.0.62520'
  205. dependency 'com.sonarsource.dbd:sonar-dbd-plugin:1.17.0.4892'
  206. dependency 'com.sonarsource.dbd:sonar-dbd-java-frontend-plugin:1.17.0.4892'
  207. dependency 'com.sonarsource.dbd:sonar-dbd-python-frontend-plugin:1.17.0.4892'
  208. dependency 'com.sonarsource.pli:sonar-pli-plugin:1.14.0.3735'
  209. dependency 'com.sonarsource.plsql:sonar-plsql-plugin:3.10.0.5282'
  210. dependency 'com.sonarsource.plugins.vb:sonar-vb-plugin:2.11.0.3706'
  211. dependency 'com.sonarsource.rpg:sonar-rpg-plugin:3.6.0.3520'
  212. dependency 'com.sonarsource.security:sonar-security-csharp-frontend-plugin:10.2.0.22608'
  213. dependency 'com.sonarsource.security:sonar-security-java-frontend-plugin:10.2.0.22608'
  214. dependency 'com.sonarsource.security:sonar-security-php-frontend-plugin:10.2.0.22608'
  215. dependency 'com.sonarsource.security:sonar-security-plugin:10.2.0.22608'
  216. dependency 'com.sonarsource.security:sonar-security-python-frontend-plugin:10.2.0.22608'
  217. dependency 'com.sonarsource.security:sonar-security-js-frontend-plugin:10.2.0.22608'
  218. dependency 'com.sonarsource.slang:sonar-apex-plugin:1.14.0.4481'
  219. dependency 'com.sonarsource.swift:sonar-swift-plugin:4.10.0.5999'
  220. dependency 'com.sonarsource.tsql:sonar-tsql-plugin:1.10.0.5799'
  221. dependency 'org.sonarsource.config:sonar-config-plugin:1.3.0.654'
  222. dependency 'org.sonarsource.dotnet:sonar-csharp-plugin:9.8.0.76515'
  223. dependency 'org.sonarsource.dotnet:sonar-vbnet-plugin:9.8.0.76515'
  224. dependency 'org.sonarsource.flex:sonar-flex-plugin:2.10.0.3458'
  225. dependency 'org.sonarsource.html:sonar-html-plugin:3.9.0.3600'
  226. dependency 'org.sonarsource.jacoco:sonar-jacoco-plugin:1.3.0.1538'
  227. dependency 'org.sonarsource.java:sonar-java-plugin:7.24.0.32100'
  228. dependency 'org.sonarsource.javascript:sonar-javascript-plugin:10.5.1.22382'
  229. dependency 'org.sonarsource.php:sonar-php-plugin:3.31.0.9993'
  230. dependency 'org.sonarsource.plugins.cayc:sonar-cayc-plugin:2.1.0.500'
  231. dependency 'org.sonarsource.python:sonar-python-plugin:4.7.0.12181'
  232. dependency 'org.sonarsource.slang:sonar-go-plugin:1.14.0.4481'
  233. dependency 'org.sonarsource.kotlin:sonar-kotlin-plugin:2.17.0.2902'
  234. dependency 'org.sonarsource.slang:sonar-ruby-plugin:1.14.0.4481'
  235. dependency 'org.sonarsource.slang:sonar-scala-plugin:1.14.0.4481'
  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.10.0.4108'
  239. dependency 'org.sonarsource.iac:sonar-iac-plugin:1.20.0.5654'
  240. dependency 'org.sonarsource.text:sonar-text-plugin:2.3.0.1632'
  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 'com.squareup.okio:okio:3.4.0'
  269. dependency 'io.prometheus:simpleclient:0.16.0'
  270. dependency 'io.prometheus:simpleclient_common:0.16.0'
  271. dependency 'io.prometheus:simpleclient_servlet:0.16.0'
  272. dependency 'com.google.code.findbugs:jsr305:3.0.2'
  273. dependency 'com.google.code.gson:gson:2.10.1'
  274. dependency('com.google.guava:guava:32.0.1-jre') {
  275. exclude 'com.google.errorprone:error_prone_annotations'
  276. exclude 'com.google.guava:listenablefuture'
  277. exclude 'com.google.j2objc:j2objc-annotations'
  278. exclude 'org.checkerframework:checker-qual'
  279. exclude 'org.codehaus.mojo:animal-sniffer-annotations'
  280. }
  281. dependency "com.google.protobuf:protobuf-java:${protobufVersion}"
  282. dependency 'com.h2database:h2:2.1.214'
  283. dependencySet(group: 'com.hazelcast', version: '5.3.1') {
  284. entry 'hazelcast'
  285. }
  286. // Documentation must be updated if mssql-jdbc is updated: https://github.com/SonarSource/sonarqube/commit/03e4773ebf6cba854cdcf57a600095f65f4f53e7
  287. dependency('com.microsoft.sqlserver:mssql-jdbc:12.2.0.jre11') {
  288. exclude 'com.fasterxml.jackson.core:jackson-databind'
  289. }
  290. dependency 'com.onelogin:java-saml:2.9.0'
  291. dependency 'com.oracle.database.jdbc:ojdbc11:23.2.0.0'
  292. dependency 'org.aspectj:aspectjtools:1.9.19'
  293. // If this gets updated the dependency on okio 3.4.0 should be reviewed
  294. dependencySet(group: 'com.squareup.okhttp3', version: '4.11.0') {
  295. entry 'okhttp'
  296. entry 'mockwebserver'
  297. entry 'okhttp-tls'
  298. }
  299. dependency 'org.json:json:20230618'
  300. dependency 'com.tngtech.java:junit-dataprovider:1.13.1'
  301. dependencySet(group: 'io.jsonwebtoken', version: '0.11.5') {
  302. entry 'jjwt-api'
  303. entry 'jjwt-impl'
  304. entry 'jjwt-jackson'
  305. }
  306. dependency 'com.auth0:java-jwt:4.4.0'
  307. dependency 'io.netty:netty-all:4.1.93.Final'
  308. dependency 'com.sun.mail:javax.mail:1.6.2'
  309. dependency 'javax.annotation:javax.annotation-api:1.3.2'
  310. dependency 'javax.inject:javax.inject:1'
  311. dependency 'javax.servlet:javax.servlet-api:4.0.1'
  312. dependency 'javax.xml.bind:jaxb-api:2.3.1'
  313. dependency 'junit:junit:4.13.2'
  314. dependency 'org.xmlunit:xmlunit-core:2.9.1'
  315. dependency 'org.xmlunit:xmlunit-matchers:2.9.1'
  316. dependency 'net.jpountz.lz4:lz4:1.3.0'
  317. dependency 'net.lightbody.bmp:littleproxy:1.1.0-beta-bmp-17'
  318. dependency 'org.awaitility:awaitility:4.2.0'
  319. dependency 'org.apache.commons:commons-csv:1.10.0'
  320. dependency 'org.apache.commons:commons-email:1.5'
  321. dependency 'com.zaxxer:HikariCP:5.0.1'
  322. dependency('org.apache.httpcomponents:httpclient:4.5.14') {
  323. exclude 'commons-logging:commons-logging'
  324. }
  325. // Be aware that Log4j is used by Elasticsearch client
  326. dependencySet(group: 'org.apache.logging.log4j', version: '2.20.0') {
  327. entry 'log4j-core'
  328. entry 'log4j-api'
  329. entry 'log4j-to-slf4j'
  330. }
  331. dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.74') {
  332. entry 'tomcat-embed-core'
  333. entry('tomcat-embed-jasper') {
  334. exclude 'org.eclipse.jdt.core.compiler:ecj'
  335. }
  336. }
  337. dependency 'org.assertj:assertj-core:3.24.2'
  338. dependency 'org.assertj:assertj-guava:3.24.2'
  339. dependency('org.codehaus.sonar:sonar-channel:4.2') {
  340. exclude 'org.slf4j:slf4j-api'
  341. }
  342. dependency 'org.codehaus.sonar:sonar-classloader:1.0'
  343. dependency 'com.fasterxml.staxmate:staxmate:2.4.0'
  344. dependencySet(group: 'org.eclipse.jetty', version: '9.4.6.v20170531') {
  345. entry 'jetty-proxy'
  346. entry 'jetty-server'
  347. entry 'jetty-servlet'
  348. }
  349. // "elasticsearchDownloadUrlFile" and "elasticsearchDownloadSha512" must also be updated in gradle.properties
  350. dependency('org.elasticsearch.client:elasticsearch-rest-high-level-client:7.17.10') {
  351. exclude 'org.apache.logging.log4j:log4j-core'
  352. }
  353. dependency 'org.elasticsearch.plugin:transport-netty4-client:7.17.10'
  354. dependency 'org.elasticsearch:mocksocket:1.2'
  355. dependency 'org.codelibs.elasticsearch.module:analysis-common:7.17.9'
  356. dependency 'org.codelibs.elasticsearch.module:reindex:7.17.9'
  357. dependency 'org.eclipse.jgit:org.eclipse.jgit:6.6.0.202305301015-r'
  358. dependency 'org.tmatesoft.svnkit:svnkit:1.10.11'
  359. dependency 'org.hamcrest:hamcrest-all:1.3'
  360. dependency 'org.jsoup:jsoup:1.16.1'
  361. dependency 'org.mindrot:jbcrypt:0.4'
  362. dependency('org.mockito:mockito-core:5.4.0') {
  363. exclude 'org.hamcrest:hamcrest-core'
  364. }
  365. dependency "org.springframework:spring-test:${springVersion}"
  366. dependency 'org.mybatis:mybatis:3.5.13'
  367. dependencySet(group: 'org.slf4j', version: '2.0.7') {
  368. entry 'jcl-over-slf4j'
  369. entry 'jul-to-slf4j'
  370. entry 'log4j-over-slf4j'
  371. entry 'slf4j-api'
  372. }
  373. dependency 'org.postgresql:postgresql:42.6.0'
  374. dependency 'org.reflections:reflections:0.10.2'
  375. dependency 'org.simpleframework:simple:5.1.6'
  376. dependency 'org.sonarsource.git.blame:git-files-blame:1.0.2.275'
  377. dependency 'org.sonarsource.orchestrator:sonar-orchestrator:3.42.0.312'
  378. dependency 'org.sonarsource.update-center:sonar-update-center-common:1.30.0.1030'
  379. dependency("org.springframework:spring-context:${springVersion}") {
  380. exclude 'commons-logging:commons-logging'
  381. }
  382. dependency ("org.springframework:spring-webmvc:${springVersion}") {
  383. exclude 'commons-logging:commons-logging'
  384. }
  385. dependency 'org.springdoc:springdoc-openapi-webmvc-core:1.7.0'
  386. dependency 'org.subethamail:subethasmtp:3.1.7'
  387. dependency 'org.yaml:snakeyaml:2.0'
  388. dependency 'org.hibernate:hibernate-validator:6.2.5.Final'
  389. dependency 'javax.el:javax.el-api:3.0.0'
  390. dependency 'org.glassfish:javax.el:3.0.0'
  391. dependency 'org.kohsuke:github-api:1.315'
  392. // please keep this list alphabetically ordered
  393. }
  394. }
  395. configurations {
  396. bbtCompile.extendsFrom testCompile
  397. bbtRuntime.extendsFrom testRuntime
  398. bbtImplementation.extendsFrom testImplementation
  399. // global exclusions
  400. all {
  401. // do not conflict with com.sun.mail:javax.mail
  402. exclude group: 'javax.mail', module: 'mail'
  403. }
  404. }
  405. tasks.withType(Javadoc) {
  406. options.addStringOption('Xdoclint:none', '-quiet')
  407. options.encoding = 'UTF-8'
  408. title = project.name + ' ' + versionWithoutBuildNumber
  409. }
  410. task sourcesJar(type: Jar, dependsOn: classes) {
  411. archiveClassifier = 'sources'
  412. from sourceSets.main.allSource
  413. }
  414. task javadocJar(type: Jar, dependsOn: javadoc) {
  415. archiveClassifier = 'javadoc'
  416. from javadoc.destinationDir
  417. }
  418. // generate code before opening project in IDE (Eclipse or Intellij)
  419. task ide() {
  420. // empty by default. Dependencies are added to the task
  421. // when needed (see protobuf modules for example)
  422. }
  423. jacocoTestReport {
  424. reports {
  425. xml.required = true
  426. csv.required = false
  427. html.required = false
  428. }
  429. }
  430. normalization {
  431. runtimeClasspath {
  432. // Following classpath resources contain volatile data that changes in each CI build (build number, commit id, time),
  433. // so we exclude them from calculation of build cache key of test tasks:
  434. ignore 'META-INF/MANIFEST.MF'
  435. ignore 'sonar-api-version.txt'
  436. ignore 'sq-version.txt'
  437. }
  438. }
  439. ext.failedTests = []
  440. test {
  441. jvmArgs '-Dfile.encoding=UTF8'
  442. maxHeapSize = '1G'
  443. systemProperty 'java.awt.headless', true
  444. testLogging {
  445. events "skipped", "failed" // verbose log for failed and skipped tests (by default the name of the tests are not logged)
  446. exceptionFormat 'full' // log the full stack trace (default is the 1st line of the stack trace)
  447. }
  448. jacoco {
  449. enabled = true // do not disable recording of code coverage, so that remote Gradle cache entry can be used locally
  450. includes = ['com.sonar.*', 'com.sonarsource.*', 'org.sonar.*', 'org.sonarqube.*', 'org.sonarsource.*']
  451. }
  452. if (project.hasProperty('maxParallelTests')) {
  453. maxParallelForks = project.maxParallelTests as int
  454. }
  455. if (project.hasProperty('parallelTests')) {
  456. // See https://guides.gradle.org/performance/#parallel_test_execution
  457. maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
  458. }
  459. afterTest { descriptor, result ->
  460. if (result.resultType == TestResult.ResultType.FAILURE) {
  461. String failedTest = " ${descriptor.className} > ${descriptor.name}"
  462. failedTests << failedTest
  463. }
  464. }
  465. }
  466. gradle.buildFinished {
  467. if (!failedTests.empty) {
  468. println "\nFailed tests:"
  469. failedTests.each { failedTest ->
  470. println failedTest
  471. }
  472. println ""
  473. }
  474. }
  475. def protoMainSrc = 'src/main/protobuf'
  476. def protoTestSrc = 'src/test/protobuf'
  477. if (file(protoMainSrc).exists() || file(protoTestSrc).exists()) {
  478. // protobuf must be applied after java
  479. apply plugin: 'com.google.protobuf'
  480. sourceSets.main.proto.srcDir protoMainSrc // in addition to the default 'src/main/proto'
  481. sourceSets.test.proto.srcDir protoTestSrc // in addition to the default 'src/test/proto'
  482. protobuf {
  483. protoc {
  484. artifact = "com.google.protobuf:protoc:${protobufVersion}"
  485. }
  486. }
  487. jar {
  488. exclude('**/*.proto')
  489. }
  490. idea {
  491. module {
  492. sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java")
  493. testSourceDirs += file("${protobuf.generatedFilesBaseDir}/test/java")
  494. generatedSourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java")
  495. generatedSourceDirs += file("${protobuf.generatedFilesBaseDir}/test/java")
  496. }
  497. }
  498. ide.dependsOn(['generateProto', 'generateTestProto'])
  499. }
  500. if (official) {
  501. jar {
  502. // do not break incremental build on non official versions
  503. manifest {
  504. attributes(
  505. 'Version': "${version}",
  506. 'Implementation-Build': System.getenv('GIT_SHA1'),
  507. 'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
  508. )
  509. }
  510. }
  511. }
  512. license {
  513. header = rootProject.file('HEADER')
  514. strictCheck true
  515. encoding = 'UTF-8'
  516. mapping {
  517. java = 'SLASHSTAR_STYLE'
  518. js = 'SLASHSTAR_STYLE'
  519. ts = 'SLASHSTAR_STYLE'
  520. tsx = 'SLASHSTAR_STYLE'
  521. css = 'SLASHSTAR_STYLE'
  522. }
  523. includes(['**/*.java', '**/*.js', '**/*.ts', '**/*.tsx', '**/*.css'])
  524. }
  525. tasks.withType(GenerateModuleMetadata) {
  526. enabled = false
  527. }
  528. publishing {
  529. publications {
  530. mavenJava(MavenPublication) {
  531. pom {
  532. name = 'SonarQube'
  533. description = project.description
  534. url = 'http://www.sonarqube.org/'
  535. organization {
  536. name = 'SonarSource'
  537. url = 'http://www.sonarsource.com'
  538. }
  539. licenses {
  540. license {
  541. name = 'GNU LGPL 3'
  542. url = 'http://www.gnu.org/licenses/lgpl.txt'
  543. distribution = 'repo'
  544. }
  545. }
  546. scm {
  547. url = 'https://github.com/SonarSource/sonarqube'
  548. }
  549. developers {
  550. developer {
  551. id = 'sonarsource-team'
  552. name = 'SonarSource Team'
  553. }
  554. }
  555. }
  556. }
  557. }
  558. }
  559. tasks.withType(Test) {
  560. configurations {
  561. utMonitoring
  562. }
  563. dependencies {
  564. testImplementation project(":ut-monitoring")
  565. utMonitoring 'org.aspectj:aspectjweaver:1.9.19'
  566. }
  567. }
  568. tasks.withType(BlackBoxTest) {
  569. jacoco.enabled = false
  570. testClassesDirs = sourceSets.bbt.output.classesDirs
  571. classpath = sourceSets.bbt.runtimeClasspath
  572. configurations {
  573. includeInTestResources
  574. }
  575. dependencies {
  576. bbtRuntimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
  577. bbtRuntimeOnly 'com.oracle.database.jdbc:ojdbc11'
  578. bbtRuntimeOnly 'org.postgresql:postgresql'
  579. bbtRuntimeOnly project(':plugins:sonar-xoo-plugin')
  580. bbtImplementation 'org.sonarsource.orchestrator:sonar-orchestrator'
  581. bbtImplementation project(":sonar-testing-harness")
  582. bbtImplementation project(":private:it-common")
  583. }
  584. }
  585. if (isNightlyBuild) {
  586. tasks.withType(Test) {
  587. doFirst {
  588. ext {
  589. aspectJWeaver = configurations.utMonitoring.resolvedConfiguration.resolvedArtifacts.find { it.name == 'aspectjweaver' }
  590. }
  591. jvmArgs "-javaagent:${aspectJWeaver.file}"
  592. }
  593. }
  594. }
  595. signing {
  596. def signingKeyId = findProperty("signingKeyId")
  597. def signingKey = findProperty("signingKey")
  598. def signingPassword = findProperty("signingPassword")
  599. useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
  600. required {
  601. return isMainBranch && gradle.taskGraph.hasTask(":artifactoryPublish")
  602. }
  603. sign publishing.publications
  604. }
  605. tasks.withType(Sign) {
  606. onlyIf {
  607. return !artifactoryPublish.skip && isMainBranch && gradle.taskGraph.hasTask(":artifactoryPublish")
  608. }
  609. }
  610. }
  611. gradle.projectsEvaluated { gradle ->
  612. // yarn_run tasks can't all run in parallel without random issues
  613. // this script ensure all yarn_run tasks run sequentially
  614. def yarnRunTasks = allprojects.findResults { it -> it.tasks.findByName('yarn_run') }
  615. yarnRunTasks.drop(1).eachWithIndex { it, i -> it.mustRunAfter(yarnRunTasks[0..i]) }
  616. }
  617. ext.osAdaptiveCommand = { commands ->
  618. def newCommands = []
  619. if (System.properties['os.name'].toLowerCase().contains('windows')) {
  620. newCommands = ['cmd', '/c']
  621. }
  622. newCommands.addAll(commands)
  623. return newCommands
  624. }
  625. tasks.named('sonarqube') {
  626. long taskStart
  627. doFirst {
  628. taskStart = System.currentTimeMillis()
  629. }
  630. doLast {
  631. long taskDuration = System.currentTimeMillis() - taskStart
  632. File outputFile = new File("/tmp/analysis-monitoring.log")
  633. outputFile.append(JsonOutput.toJson([category: "Analysis", suite: "Standalone", operation: "total", duration: taskDuration]) + '\n')
  634. }
  635. }