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

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