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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  1. plugins {
  2. // Ordered alphabeticly
  3. id 'com.github.ben-manes.versions' version '0.33.0'
  4. id 'com.github.hierynomus.license' version '0.15.0'
  5. id "com.github.hierynomus.license-report" version"0.15.0" apply false
  6. id 'com.github.johnrengelman.shadow' version '5.2.0' apply false
  7. id 'com.google.protobuf' version '0.8.13' apply false
  8. id 'com.jfrog.artifactory' version '4.21.0'
  9. id 'io.spring.dependency-management' version '1.0.10.RELEASE'
  10. id "com.asarkar.gradle.build-time-tracker" version "2.0.4" apply false
  11. id 'org.owasp.dependencycheck' version '6.3.1'
  12. id 'org.sonarqube' version '3.0'
  13. id "de.undercouch.download" version "4.1.1" apply false
  14. }
  15. // display a summary of task durations at the end of the build
  16. if (project.hasProperty('time-tracker')) {
  17. apply plugin: 'com.asarkar.gradle.build-time-tracker'
  18. buildTimeTracker {
  19. sort = true
  20. maxWidth = 80
  21. minTaskDuration = Duration.ofSeconds(1)
  22. }
  23. }
  24. if (!JavaVersion.current().java11Compatible) {
  25. throw new GradleException("JDK 11+ is required to perform this build. It's currently " + System.getProperty("java.home") + ".")
  26. }
  27. apply plugin: 'org.owasp.dependencycheck'
  28. dependencyCheck {
  29. analyzers {
  30. assemblyEnabled = false
  31. autoconfEnabled = false
  32. bundleAuditEnabled = false
  33. cmakeEnabled = false
  34. cocoapodsEnabled = false
  35. composerEnabled = false
  36. cocoapodsEnabled = false
  37. golangDepEnabled = false
  38. golangModEnabled = false
  39. nodeAudit {
  40. skipDevDependencies = true
  41. }
  42. nuspecEnabled = false
  43. nugetconfEnabled = false
  44. rubygemsEnabled = false
  45. swiftEnabled = false
  46. }
  47. format = 'ALL'
  48. junitFailOnCVSS = 0
  49. failBuildOnCVSS = 0
  50. suppressionFiles = ["${project.rootDir}/private/owasp/suppressions.xml", "${project.rootDir}/private/owasp/vulnerabilities.xml"]
  51. skipProjects = project.subprojects
  52. .findAll {it.name.contains('testing') ||
  53. it.name.startsWith('it-') ||
  54. it.name.contains('-test') ||
  55. it.name == 'sonar-ws-generator'}
  56. .collect { it.path }
  57. }
  58. allprojects {
  59. apply plugin: 'com.jfrog.artifactory'
  60. apply plugin: 'maven-publish'
  61. ext.versionInSources = version
  62. ext.buildNumber = System.getProperty("buildNumber")
  63. // when no buildNumber is provided, then project version must end with '-SNAPSHOT'
  64. if (ext.buildNumber == null) {
  65. version = "${version}-SNAPSHOT".toString()
  66. ext.versionWithoutBuildNumber = version
  67. } else {
  68. ext.versionWithoutBuildNumber = version
  69. version = (version.toString().count('.') == 1 ? "${version}.0.${ext.buildNumber}" : "${version}.${ext.buildNumber}").toString()
  70. }
  71. ext {
  72. release = project.hasProperty('release') && project.getProperty('release')
  73. official = project.hasProperty('official') && project.getProperty('official')
  74. }
  75. repositories {
  76. def repository = project.hasProperty('qa') ? 'sonarsource-qa' : 'sonarsource'
  77. maven {
  78. // The environment variables ARTIFACTORY_PRIVATE_USERNAME and ARTIFACTORY_PRIVATE_PASSWORD are used on QA env (Jenkins)
  79. // On local box, please add artifactoryUsername and artifactoryPassword to ~/.gradle/gradle.properties
  80. def artifactoryUsername = System.env.'ARTIFACTORY_PRIVATE_USERNAME' ?: (project.hasProperty('artifactoryUsername') ? project.getProperty('artifactoryUsername') : '')
  81. def artifactoryPassword = System.env.'ARTIFACTORY_PRIVATE_PASSWORD' ?: (project.hasProperty('artifactoryPassword') ? project.getProperty('artifactoryPassword') : '')
  82. if (artifactoryUsername && artifactoryPassword) {
  83. credentials {
  84. username artifactoryUsername
  85. password artifactoryPassword
  86. }
  87. } else {
  88. // Workaround for artifactory
  89. // https://www.jfrog.com/jira/browse/RTFACT-13797
  90. repository = 'public'
  91. }
  92. url "https://repox.jfrog.io/repox/${repository}"
  93. }
  94. }
  95. task allDependencies {
  96. dependsOn 'dependencies'
  97. }
  98. artifactory {
  99. clientConfig.setIncludeEnvVars(true)
  100. clientConfig.setEnvVarsExcludePatterns('*password*,*PASSWORD*,*secret*,*MAVEN_CMD_LINE_ARGS*,sun.java.command,*token*,*TOKEN*,*LOGIN*,*login*,*key*,*KEY*,*signing*')
  101. contextUrl = System.getenv('ARTIFACTORY_URL')
  102. publish {
  103. repository {
  104. repoKey = System.getenv('ARTIFACTORY_DEPLOY_REPO')
  105. username = System.getenv('ARTIFACTORY_DEPLOY_USERNAME') ?: project.properties.artifactoryUsername
  106. password = System.getenv('ARTIFACTORY_DEPLOY_PASSWORD') ?: project.properties.artifactoryPaswword
  107. }
  108. defaults {
  109. properties = [
  110. 'build.name': 'sonar-enterprise',
  111. 'build.number': System.getenv('BUILD_NUMBER'),
  112. 'pr.branch.target': System.getenv('GITHUB_BASE_BRANCH'),
  113. 'pr.number': System.getenv('PULL_REQUEST'),
  114. 'vcs.branch': System.getenv('GITHUB_BRANCH'),
  115. 'vcs.revision': System.getenv('GIT_SHA1'),
  116. 'version': version
  117. ]
  118. publications('mavenJava')
  119. publishPom = true
  120. publishIvy = false
  121. }
  122. }
  123. clientConfig.info.setBuildName('sonar-enterprise')
  124. clientConfig.info.setBuildNumber(System.getenv('BUILD_NUMBER'))
  125. // Define the artifacts to be deployed to https://binaries.sonarsource.com on releases
  126. clientConfig.info.addEnvironmentProperty('ARTIFACTS_TO_PUBLISH',
  127. "${project.group}:sonar-application:zip," +
  128. "com.sonarsource.sonarqube:sonarqube-developer:zip," +
  129. "com.sonarsource.sonarqube:sonarqube-datacenter:zip," +
  130. "com.sonarsource.sonarqube:sonarqube-enterprise:zip")
  131. // The name of this variable is important because it's used by the delivery process when extracting version from Artifactory build info.
  132. clientConfig.info.addEnvironmentProperty('PROJECT_VERSION', "${version}")
  133. }
  134. }
  135. apply plugin: 'org.sonarqube'
  136. sonarqube {
  137. properties {
  138. property 'sonar.projectName', projectTitle
  139. property 'sonar.projectVersion', "${versionInSources}-SNAPSHOT"
  140. property 'sonar.buildString', version
  141. }
  142. }
  143. tasks.named('wrapper') {
  144. distributionType = Wrapper.DistributionType.ALL
  145. }
  146. subprojects {
  147. apply plugin: 'com.github.hierynomus.license'
  148. apply plugin: 'io.spring.dependency-management'
  149. apply plugin: 'jacoco'
  150. apply plugin: 'java'
  151. apply plugin: 'idea'
  152. apply plugin: 'signing'
  153. // do not deploy to Artifactory by default
  154. artifactoryPublish.skip = true
  155. def testFixtureSrc = 'src/testFixtures'
  156. if (file(testFixtureSrc).exists()) {
  157. apply plugin: 'java-test-fixtures'
  158. }
  159. ext {
  160. protobufVersion = '3.17.3'
  161. // define a method which can be called by project to change Java version to compile to
  162. configureCompileJavaToVersion = { javaVersion ->
  163. if ( javaVersion != 11 & javaVersion != 8) {
  164. throw new InvalidUserDataException("Only Java 8 and 11 are supported")
  165. }
  166. if ( javaVersion == 8 ) {
  167. println "Configuring project ${project.name} to compile to Java ${javaVersion}"
  168. if (!project.hasProperty('skipJava8Checks')) {
  169. task ensureDependenciesRunOnJava8(dependsOn: [configurations.compileClasspath]) {
  170. ext.readJavaMajorVersion = { classFile ->
  171. classFile.withDataInputStream({ d ->
  172. if (d.skip(7) == 7) {
  173. // read the version of the class file
  174. d.read()
  175. } else {
  176. throw new GradleException("Could not read major version from $classFile")
  177. }
  178. })
  179. }
  180. doLast {
  181. [configurations.compileClasspath].each { config ->
  182. config.resolvedConfiguration.files
  183. .findAll({ f -> f.name.endsWith("jar") })
  184. .each { jarFile ->
  185. def onlyJava8 = true
  186. zipTree(jarFile)
  187. .matching({
  188. include "**/*.class"
  189. // multi-release jar files were introduced with Java 9 => contains only classes targeting Java 9+
  190. exclude "META-INF/versions/**"
  191. // ignore module-info existing in some archives for Java 9 forward compatibility
  192. exclude "module-info.class"
  193. })
  194. .files
  195. .each { classFile ->
  196. int javaMajorVersion = readJavaMajorVersion(classFile)
  197. if (javaMajorVersion > 52) {
  198. println "$classFile has been compiled to a more recent version of Java than 8 (java8=52, java11=55, actual=$javaMajorVersion)"
  199. onlyJava8 = false
  200. }
  201. }
  202. if (!onlyJava8) {
  203. throw new GradleException("Dependency ${jarFile} in configuration ${config.name} contains class file(s) compiled to a Java version > Java 8 (see logs for details)")
  204. }
  205. }
  206. }
  207. }
  208. }
  209. compileJava.dependsOn ensureDependenciesRunOnJava8
  210. }
  211. }
  212. sourceCompatibility = javaVersion
  213. targetCompatibility = javaVersion
  214. tasks.withType(JavaCompile) {
  215. options.compilerArgs.addAll(['--release', javaVersion + ''])
  216. options.encoding = 'UTF-8'
  217. }
  218. }
  219. }
  220. configureCompileJavaToVersion 11
  221. sonarqube {
  222. properties {
  223. property 'sonar.moduleKey', project.group + ':' + project.name
  224. }
  225. }
  226. // Central place for definition dependency versions and exclusions.
  227. dependencyManagement {
  228. dependencies {
  229. // bundled plugin list -- keep it alphabetically ordered
  230. dependency 'com.sonarsource.abap:sonar-abap-plugin:3.9.1.3127'
  231. dependency 'com.sonarsource.cobol:sonar-cobol-plugin:4.6.2.4876'
  232. dependency 'com.sonarsource.cpp:sonar-cfamily-plugin:6.28.0.39490'
  233. dependency 'com.sonarsource.pli:sonar-pli-plugin:1.11.1.2727'
  234. dependency 'com.sonarsource.plsql:sonar-plsql-plugin:3.6.1.3873'
  235. dependency 'com.sonarsource.plugins.vb:sonar-vb-plugin:2.7.1.2721'
  236. dependency 'com.sonarsource.rpg:sonar-rpg-plugin:3.1.0.2955'
  237. dependency 'com.sonarsource.security:sonar-security-csharp-frontend-plugin:9.2.0.14426'
  238. dependency 'com.sonarsource.security:sonar-security-java-frontend-plugin:9.2.0.14426'
  239. dependency 'com.sonarsource.security:sonar-security-php-frontend-plugin:9.2.0.14426'
  240. dependency 'com.sonarsource.security:sonar-security-plugin:9.2.0.14426'
  241. dependency 'com.sonarsource.security:sonar-security-python-frontend-plugin:9.2.0.14426'
  242. dependency 'com.sonarsource.security:sonar-security-js-frontend-plugin:9.2.0.14426'
  243. dependency 'com.sonarsource.slang:sonar-apex-plugin:1.8.3.2219'
  244. dependency 'com.sonarsource.swift:sonar-swift-plugin:4.3.2.5043'
  245. dependency 'com.sonarsource.tsql:sonar-tsql-plugin:1.5.1.4340'
  246. dependency 'org.sonarsource.config:sonar-config-plugin:1.1.0.185'
  247. dependency 'org.sonarsource.dotnet:sonar-csharp-plugin:8.32.0.39516'
  248. dependency 'org.sonarsource.dotnet:sonar-vbnet-plugin:8.32.0.39516'
  249. dependency 'org.sonarsource.flex:sonar-flex-plugin:2.6.2.2641'
  250. dependency 'org.sonarsource.html:sonar-html-plugin:3.4.0.2754'
  251. dependency 'org.sonarsource.jacoco:sonar-jacoco-plugin:1.1.1.1157'
  252. dependency 'org.sonarsource.java:sonar-java-plugin:7.5.0.28054'
  253. dependency 'org.sonarsource.javascript:sonar-javascript-plugin:8.6.0.16913'
  254. dependency 'org.sonarsource.php:sonar-php-plugin:3.21.2.8292'
  255. dependency 'org.sonarsource.python:sonar-python-plugin:3.8.0.8883'
  256. dependency 'org.sonarsource.slang:sonar-go-plugin:1.8.3.2219'
  257. dependency 'org.sonarsource.kotlin:sonar-kotlin-plugin:2.7.0.948'
  258. dependency 'org.sonarsource.slang:sonar-ruby-plugin:1.8.3.2219'
  259. dependency 'org.sonarsource.slang:sonar-scala-plugin:1.8.3.2219'
  260. dependency 'org.sonarsource.xml:sonar-xml-plugin:2.4.0.3273'
  261. dependency 'org.sonarsource.iac:sonar-iac-plugin:1.4.0.1294'
  262. // please keep this list alphabetically ordered
  263. dependencySet(group: 'ch.qos.logback', version: '1.2.3') {
  264. entry 'logback-access'
  265. entry 'logback-classic'
  266. entry 'logback-core'
  267. }
  268. dependency('commons-beanutils:commons-beanutils:1.8.3') {
  269. exclude 'commons-logging:commons-logging'
  270. }
  271. dependency 'commons-codec:commons-codec:1.14'
  272. dependency 'commons-dbutils:commons-dbutils:1.7'
  273. dependency 'commons-io:commons-io:2.8.0'
  274. dependency 'commons-lang:commons-lang:2.6'
  275. imports { mavenBom 'com.fasterxml.jackson:jackson-bom:2.11.4' }
  276. dependencySet(group: 'com.fasterxml.jackson.dataformat', version: '2.11.4') {
  277. entry 'jackson-dataformat-cbor'
  278. entry 'jackson-dataformat-smile'
  279. entry 'jackson-dataformat-yaml'
  280. }
  281. dependency 'com.eclipsesource.minimal-json:minimal-json:0.9.5'
  282. dependencySet(group: 'com.github.scribejava', version: '6.9.0') {
  283. entry 'scribejava-apis'
  284. entry 'scribejava-core'
  285. }
  286. dependency 'com.github.everit-org.json-schema:org.everit.json.schema:1.12.2'
  287. // This project is no longer maintained and was forked
  288. // by https://github.com/java-diff-utils/java-diff-utils
  289. // (io.github.java-diff-utils:java-diff-utils).
  290. dependency 'com.googlecode.java-diff-utils:diffutils:1.2'
  291. dependency('com.googlecode.json-simple:json-simple:1.1.1') {
  292. exclude 'junit:junit'
  293. }
  294. dependency 'com.google.code.findbugs:jsr305:3.0.2'
  295. dependency 'com.google.code.gson:gson:2.8.6'
  296. dependency('com.google.guava:guava:28.2-jre') {
  297. exclude 'com.google.errorprone:error_prone_annotations'
  298. exclude 'com.google.guava:listenablefuture'
  299. exclude 'com.google.j2objc:j2objc-annotations'
  300. exclude 'org.checkerframework:checker-qual'
  301. exclude 'org.codehaus.mojo:animal-sniffer-annotations'
  302. }
  303. dependency "com.google.protobuf:protobuf-java:${protobufVersion}"
  304. // Do not upgrade H2 to 1.4.200 because of instability: https://github.com/h2database/h2database/issues/2205
  305. dependency 'com.h2database:h2:1.4.199'
  306. dependencySet(group: 'com.hazelcast', version: '4.2') {
  307. entry 'hazelcast'
  308. }
  309. dependency 'com.hazelcast:hazelcast-kubernetes:2.2.3'
  310. dependency 'com.ibm.icu:icu4j:3.4.4'
  311. // Documentation must be updated if mssql-jdbc is updated: https://github.com/SonarSource/sonarqube/commit/03e4773ebf6cba854cdcf57a600095f65f4f53e7
  312. dependency 'com.microsoft.sqlserver:mssql-jdbc:9.2.0.jre11'
  313. dependency 'com.oracle.database.jdbc:ojdbc8:19.3.0.0'
  314. // upgrade okhttp3 dependency kotlin to get rid of not exploitable CVE-2020-29582
  315. dependency 'org.jetbrains.kotlin:kotlin-stdlib-common:1.4.21'
  316. dependency 'org.jetbrains.kotlin:kotlin-stdlib:1.4.21'
  317. dependencySet(group: 'com.squareup.okhttp3', version: '4.9.0') {
  318. entry 'okhttp'
  319. entry 'mockwebserver'
  320. }
  321. dependency 'com.tngtech.java:junit-dataprovider:1.13.1'
  322. dependency 'info.picocli:picocli:3.6.1'
  323. dependencySet(group: 'io.jsonwebtoken', version: '0.11.2') {
  324. entry 'jjwt-api'
  325. entry 'jjwt-impl'
  326. entry 'jjwt-jackson'
  327. }
  328. dependency 'com.auth0:java-jwt:3.10.3'
  329. dependency 'io.netty:netty-all:4.1.70.Final'
  330. dependency 'com.sun.mail:javax.mail:1.5.6'
  331. dependency 'javax.annotation:javax.annotation-api:1.3.2'
  332. dependency 'javax.servlet:javax.servlet-api:3.1.0'
  333. dependency 'javax.xml.bind:jaxb-api:2.3.0'
  334. dependency 'junit:junit:4.13.1'
  335. dependency 'org.junit.jupiter:junit-jupiter-api:5.6.0'
  336. dependency 'org.xmlunit:xmlunit-core:2.6.4'
  337. dependency 'org.xmlunit:xmlunit-matchers:2.6.4'
  338. dependency 'net.jpountz.lz4:lz4:1.3.0'
  339. dependency 'net.lightbody.bmp:littleproxy:1.1.0-beta-bmp-17'
  340. dependency 'org.awaitility:awaitility:4.0.2'
  341. dependency 'org.apache.commons:commons-csv:1.7'
  342. dependency 'org.apache.commons:commons-email:1.5'
  343. dependency 'org.apache.commons:commons-dbcp2:2.9.0'
  344. dependency('org.apache.httpcomponents:httpclient:4.5.13'){
  345. exclude 'commons-logging:commons-logging'
  346. }
  347. // Be aware that Log4j is used by Elasticsearch client
  348. dependencySet(group: 'org.apache.logging.log4j', version: '2.16.0') {
  349. entry 'log4j-core'
  350. entry 'log4j-api'
  351. entry 'log4j-to-slf4j'
  352. }
  353. dependencySet(group: 'org.apache.tomcat.embed', version: '8.5.72') {
  354. entry 'tomcat-embed-core'
  355. entry('tomcat-embed-jasper') {
  356. exclude 'org.eclipse.jdt.core.compiler:ecj'
  357. }
  358. }
  359. dependency 'org.assertj:assertj-core:3.15.0'
  360. dependency 'org.assertj:assertj-guava:3.3.0'
  361. dependency('org.codehaus.sonar:sonar-channel:4.2') {
  362. exclude 'org.slf4j:slf4j-api'
  363. }
  364. dependency 'org.codehaus.sonar:sonar-classloader:1.0'
  365. dependency 'com.fasterxml.staxmate:staxmate:2.4.0'
  366. dependencySet(group: 'org.eclipse.jetty', version: '9.4.6.v20170531') {
  367. entry 'jetty-proxy'
  368. entry 'jetty-server'
  369. entry 'jetty-servlet'
  370. }
  371. dependency('org.elasticsearch.client:elasticsearch-rest-high-level-client:7.16.0') {
  372. exclude 'org.apache.logging.log4j:log4j-core'
  373. }
  374. dependency 'org.elasticsearch.plugin:transport-netty4-client:7.16.0'
  375. dependency 'org.elasticsearch:mocksocket:1.0'
  376. dependency 'org.codelibs.elasticsearch.module:analysis-common:7.16.0'
  377. dependency 'org.eclipse.jgit:org.eclipse.jgit:5.11.0.202103091610-r'
  378. dependency 'org.tmatesoft.svnkit:svnkit:1.10.1'
  379. dependency 'org.hamcrest:hamcrest-all:1.3'
  380. dependency 'org.jsoup:jsoup:1.13.1'
  381. dependency 'org.mindrot:jbcrypt:0.4'
  382. dependency('org.mockito:mockito-core:3.3.3') {
  383. exclude 'org.hamcrest:hamcrest-core'
  384. }
  385. dependency 'org.mybatis:mybatis:3.5.6'
  386. dependency 'org.nanohttpd:nanohttpd:2.3.1'
  387. dependency 'org.picocontainer:picocontainer:2.15'
  388. dependencySet(group: 'org.slf4j', version: '1.7.30') {
  389. entry 'jcl-over-slf4j'
  390. entry 'jul-to-slf4j'
  391. entry 'log4j-over-slf4j'
  392. entry 'slf4j-api'
  393. }
  394. dependency 'org.postgresql:postgresql:42.2.19'
  395. dependency 'org.reflections:reflections:0.9.12'
  396. dependency 'org.simpleframework:simple:4.1.21'
  397. dependency 'org.sonarsource.orchestrator:sonar-orchestrator:3.35.1.2719'
  398. dependency 'org.sonarsource.update-center:sonar-update-center-common:1.23.0.723'
  399. dependency 'org.subethamail:subethasmtp:3.1.7'
  400. dependency 'org.yaml:snakeyaml:1.26'
  401. dependency 'xml-apis:xml-apis:1.4.01'
  402. // please keep this list alphabetically ordered
  403. }
  404. }
  405. // global exclusions
  406. configurations.all {
  407. // do not conflict with com.sun.mail:javax.mail
  408. exclude group: 'javax.mail', module: 'mail'
  409. }
  410. tasks.withType(Javadoc) {
  411. options.addStringOption('Xdoclint:none', '-quiet')
  412. options.encoding = 'UTF-8'
  413. doFirst {
  414. options.addBooleanOption('-no-module-directories', true)
  415. }
  416. title = project.name + ' ' + versionWithoutBuildNumber
  417. }
  418. task sourcesJar(type: Jar, dependsOn: classes) {
  419. archiveClassifier = 'sources'
  420. from sourceSets.main.allSource
  421. }
  422. task javadocJar(type: Jar, dependsOn: javadoc) {
  423. archiveClassifier = 'javadoc'
  424. from javadoc.destinationDir
  425. }
  426. // generate code before opening project in IDE (Eclipse or Intellij)
  427. task ide() {
  428. // empty by default. Dependencies are added to the task
  429. // when needed (see protobuf modules for example)
  430. }
  431. jacocoTestReport {
  432. reports {
  433. xml.required = true
  434. csv.required = false
  435. html.required = false
  436. }
  437. }
  438. normalization {
  439. runtimeClasspath {
  440. // Following classpath resources contain volatile data that changes in each CI build (build number, commit id, time),
  441. // so we exclude them from calculation of build cache key of test tasks:
  442. ignore 'META-INF/MANIFEST.MF'
  443. ignore 'sonar-api-version.txt'
  444. ignore 'sq-version.txt'
  445. }
  446. }
  447. ext.failedTests = []
  448. test {
  449. jvmArgs '-Dfile.encoding=UTF8'
  450. maxHeapSize = '1G'
  451. systemProperty 'java.awt.headless', true
  452. testLogging {
  453. events "skipped", "failed" // verbose log for failed and skipped tests (by default the name of the tests are not logged)
  454. exceptionFormat 'full' // log the full stack trace (default is the 1st line of the stack trace)
  455. }
  456. jacoco {
  457. enabled = true // do not disable recording of code coverage, so that remote Gradle cache entry can be used locally
  458. includes = ['com.sonar.*', 'com.sonarsource.*', 'org.sonar.*', 'org.sonarqube.*', 'org.sonarsource.*']
  459. }
  460. if (project.hasProperty('maxParallelTests')) {
  461. maxParallelForks = project.maxParallelTests as int
  462. }
  463. if (project.hasProperty('parallelTests')) {
  464. // See https://guides.gradle.org/performance/#parallel_test_execution
  465. maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
  466. }
  467. afterTest { descriptor, result ->
  468. if (result.resultType == TestResult.ResultType.FAILURE) {
  469. String failedTest = " ${descriptor.className} > ${descriptor.name}"
  470. failedTests << failedTest
  471. }
  472. }
  473. }
  474. gradle.buildFinished {
  475. if (!failedTests.empty) {
  476. println "\nFailed tests:"
  477. failedTests.each { failedTest ->
  478. println failedTest
  479. }
  480. println ""
  481. }
  482. }
  483. def protoMainSrc = 'src/main/protobuf'
  484. def protoTestSrc = 'src/test/protobuf'
  485. if (file(protoMainSrc).exists() || file(protoTestSrc).exists()) {
  486. // protobuf must be applied after java
  487. apply plugin: 'com.google.protobuf'
  488. sourceSets.main.proto.srcDir protoMainSrc // in addition to the default 'src/main/proto'
  489. sourceSets.test.proto.srcDir protoTestSrc // in addition to the default 'src/test/proto'
  490. protobuf {
  491. protoc {
  492. artifact = "com.google.protobuf:protoc:${protobufVersion}"
  493. }
  494. }
  495. jar {
  496. exclude('**/*.proto')
  497. }
  498. idea {
  499. module {
  500. sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java")
  501. testSourceDirs += file("${protobuf.generatedFilesBaseDir}/test/java")
  502. generatedSourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java")
  503. generatedSourceDirs += file("${protobuf.generatedFilesBaseDir}/test/java")
  504. }
  505. }
  506. ide.dependsOn(['generateProto', 'generateTestProto'])
  507. }
  508. if (official) {
  509. jar {
  510. // do not break incremental build on non official versions
  511. manifest {
  512. attributes(
  513. 'Version': "${version}",
  514. 'Implementation-Build': System.getenv('GIT_SHA1'),
  515. 'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
  516. )
  517. }
  518. }
  519. }
  520. license {
  521. header = rootProject.file('HEADER')
  522. strictCheck true
  523. mapping {
  524. java = 'SLASHSTAR_STYLE'
  525. js = 'SLASHSTAR_STYLE'
  526. ts = 'SLASHSTAR_STYLE'
  527. tsx = 'SLASHSTAR_STYLE'
  528. css = 'SLASHSTAR_STYLE'
  529. }
  530. includes(['**/*.java', '**/*.js', '**/*.ts', '**/*.tsx', '**/*.css'])
  531. }
  532. tasks.withType(GenerateModuleMetadata) {
  533. enabled = false
  534. }
  535. publishing {
  536. publications {
  537. mavenJava(MavenPublication) {
  538. pom {
  539. name = 'SonarQube'
  540. description = project.description
  541. url = 'http://www.sonarqube.org/'
  542. organization {
  543. name = 'SonarSource'
  544. url = 'http://www.sonarsource.com'
  545. }
  546. licenses {
  547. license {
  548. name = 'GNU LGPL 3'
  549. url = 'http://www.gnu.org/licenses/lgpl.txt'
  550. distribution = 'repo'
  551. }
  552. }
  553. scm {
  554. url = 'https://github.com/SonarSource/sonarqube'
  555. }
  556. developers {
  557. developer {
  558. id = 'sonarsource-team'
  559. name = 'SonarSource Team'
  560. }
  561. }
  562. }
  563. }
  564. }
  565. }
  566. signing {
  567. def signingKeyId = findProperty("signingKeyId")
  568. def signingKey = findProperty("signingKey")
  569. def signingPassword = findProperty("signingPassword")
  570. useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
  571. required {
  572. def branch = System.getenv()["CIRRUS_BRANCH"]
  573. return (branch in ['master', 'dogfood-on-next'] || branch ==~ 'branch-[\\d.]+') &&
  574. gradle.taskGraph.hasTask(":artifactoryPublish")
  575. }
  576. sign publishing.publications
  577. }
  578. tasks.withType(Sign) {
  579. onlyIf {
  580. def branch = System.getenv()["CIRRUS_BRANCH"]
  581. return !artifactoryPublish.skip &&
  582. (branch in ['master', 'dogfood-on-next'] || branch ==~ 'branch-[\\d.]+') &&
  583. gradle.taskGraph.hasTask(":artifactoryPublish")
  584. }
  585. }
  586. }
  587. // https://github.com/ben-manes/gradle-versions-plugin
  588. apply plugin: 'com.github.ben-manes.versions'
  589. dependencyUpdates {
  590. rejectVersionIf {
  591. // Exclude dev versions from the list of dependency upgrades, for
  592. // example to replace:
  593. // org.slf4j:log4j-over-slf4j [1.7.25 -> 1.8.0-beta4]
  594. // by
  595. // org.slf4j:log4j-over-slf4j [1.7.25 -> 1.7.26]
  596. boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm', 'preview', 'jre12'].any { qualifier ->
  597. it.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
  598. }
  599. // Exclude upgrades on new major versions :
  600. // com.hazelcast:hazelcast [3.12.3 -> 4.0.0]
  601. rejected |= !it.candidate.version.substring(0, 2).equals(it.currentVersion.substring(0, 2))
  602. rejected
  603. }
  604. }
  605. gradle.projectsEvaluated { gradle ->
  606. // Execute dependencyCheckAggregate prerequisites before the actual check
  607. allprojects
  608. .findResults { it -> it.tasks.findByName('dependencyCheckAggregate_prerequisites') }
  609. .each { t -> dependencyCheckAggregate.dependsOn(t) }
  610. // yarn_run tasks can't all run in parallel without random issues
  611. // this script ensure all yarn_run tasks run sequentially
  612. def yarnRunTasks = allprojects.findResults { it -> it.tasks.findByName('yarn_run') }
  613. yarnRunTasks.drop(1).eachWithIndex { it, i -> it.mustRunAfter(yarnRunTasks[0..i]) }
  614. }
  615. ext.osAdaptiveCommand = { commands ->
  616. def newCommands = []
  617. if (System.properties['os.name'].toLowerCase().contains('windows')) {
  618. newCommands = ['cmd', '/c']
  619. }
  620. newCommands.addAll(commands)
  621. return newCommands
  622. }