You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

build.gradle 25KB

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