Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

build.gradle 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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.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.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.24.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.11') {
  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.16.0'
  253. dependency 'commons-dbutils:commons-dbutils:1.8.0'
  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.5.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.2') {
  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.4.1.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.20.1'
  295. // If this gets updated the dependency on okio 3.5.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.97.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. dependency('org.elasticsearch.client:elasticsearch-rest-high-level-client:7.17.12') {
  352. exclude 'org.apache.logging.log4j:log4j-core'
  353. }
  354. dependency 'org.elasticsearch.plugin:transport-netty4-client:7.17.12'
  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.1.202309021850-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.5.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.9') {
  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-junit4:4.1.0.495'
  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.2'
  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.316'
  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. testMonitoring
  587. }
  588. dependencies {
  589. testImplementation project(":ut-monitoring")
  590. testImplementation project(":test-monitoring")
  591. utMonitoring 'org.aspectj:aspectjweaver:1.9.20.1'
  592. testMonitoring 'org.aspectj:aspectjweaver:1.9.20.1'
  593. }
  594. }
  595. tasks.withType(BlackBoxTest) {
  596. jacoco.enabled = false
  597. testClassesDirs = sourceSets.bbt.output.classesDirs
  598. classpath = sourceSets.bbt.runtimeClasspath
  599. configurations {
  600. includeInTestResources
  601. }
  602. dependencies {
  603. bbtRuntimeOnly 'com.microsoft.sqlserver:mssql-jdbc'
  604. bbtRuntimeOnly 'com.oracle.database.jdbc:ojdbc11'
  605. bbtRuntimeOnly 'org.postgresql:postgresql'
  606. bbtRuntimeOnly project(':plugins:sonar-xoo-plugin')
  607. bbtImplementation 'org.sonarsource.orchestrator:sonar-orchestrator-junit4'
  608. bbtImplementation project(":sonar-testing-harness")
  609. bbtImplementation project(":private:it-common")
  610. }
  611. }
  612. if (isNightlyBuild) {
  613. tasks.withType(Test) {
  614. doFirst {
  615. ext {
  616. aspectJWeaver = configurations.utMonitoring.resolvedConfiguration.resolvedArtifacts.find { it.name == 'aspectjweaver' }
  617. }
  618. jvmArgs "-javaagent:${aspectJWeaver.file}"
  619. }
  620. }
  621. }
  622. if (ext.withTestMonitoring) {
  623. tasks.withType(Test) {
  624. doFirst {
  625. ext {
  626. aspectJWeaver = configurations.testMonitoring.resolvedConfiguration.resolvedArtifacts.find { it.name == 'aspectjweaver' }
  627. }
  628. jvmArgs "-javaagent:${aspectJWeaver.file}"
  629. }
  630. }
  631. }
  632. signing {
  633. def signingKeyId = findProperty("signingKeyId")
  634. def signingKey = findProperty("signingKey")
  635. def signingPassword = findProperty("signingPassword")
  636. useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
  637. required {
  638. return isMainBranch && gradle.taskGraph.hasTask(":artifactoryPublish")
  639. }
  640. sign publishing.publications
  641. }
  642. tasks.withType(Sign) {
  643. onlyIf {
  644. return !artifactoryPublish.skip && isMainBranch && gradle.taskGraph.hasTask(":artifactoryPublish")
  645. }
  646. }
  647. }
  648. static def applyPackageInfoTemplate(packageName) {
  649. def engine = new SimpleTemplateEngine()
  650. def templateText = "@ParametersAreNonnullByDefault\n" +
  651. "package $packageName;\n" +
  652. "\n" +
  653. "import javax.annotation.ParametersAreNonnullByDefault;\n"
  654. def templateParams = ["packageName": packageName]
  655. engine.createTemplate(templateText).make(templateParams).toString()
  656. }
  657. gradle.projectsEvaluated { gradle ->
  658. // yarn_run tasks can't all run in parallel without random issues
  659. // this script ensure all yarn_run tasks run sequentially
  660. def yarnRunTasks = allprojects.findResults { it -> it.tasks.findByName('yarn_run') }
  661. yarnRunTasks.drop(1).eachWithIndex { it, i -> it.mustRunAfter(yarnRunTasks[0..i]) }
  662. }
  663. ext.osAdaptiveCommand = { commands ->
  664. def newCommands = []
  665. if (System.properties['os.name'].toLowerCase().contains('windows')) {
  666. newCommands = ['cmd', '/c']
  667. }
  668. newCommands.addAll(commands)
  669. return newCommands
  670. }
  671. tasks.named('sonarqube') {
  672. long taskStart
  673. doFirst {
  674. taskStart = System.currentTimeMillis()
  675. }
  676. doLast {
  677. long taskDuration = System.currentTimeMillis() - taskStart
  678. File outputFile = new File("/tmp/analysis-monitoring.log")
  679. outputFile.append(JsonOutput.toJson([category: "Analysis", suite: "Standalone", operation: "total", duration: taskDuration]) + '\n')
  680. }
  681. }