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

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