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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. import groovy.json.JsonOutput
  2. plugins {
  3. // Ordered alphabeticly
  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.18' apply false
  8. id 'com.jfrog.artifactory' version '4.24.23'
  9. id 'io.spring.dependency-management' version '1.0.11.RELEASE'
  10. id 'org.sonarqube' version '3.3'
  11. id "de.undercouch.download" version "5.0.1" apply false
  12. }
  13. if (!JavaVersion.current().java11Compatible) {
  14. throw new GradleException("JDK 11+ is required to perform this build. It's currently " + System.getProperty("java.home") + ".")
  15. }
  16. allprojects {
  17. apply plugin: 'com.jfrog.artifactory'
  18. apply plugin: 'maven-publish'
  19. ext.versionInSources = version
  20. ext.buildNumber = System.getProperty("buildNumber")
  21. // when no buildNumber is provided, then project version must end with '-SNAPSHOT'
  22. if (ext.buildNumber == null) {
  23. version = "${version}-SNAPSHOT".toString()
  24. ext.versionWithoutBuildNumber = version
  25. } else {
  26. ext.versionWithoutBuildNumber = version
  27. version = (version.toString().count('.') == 1 ? "${version}.0.${ext.buildNumber}" : "${version}.${ext.buildNumber}").toString()
  28. }
  29. ext {
  30. release = project.hasProperty('release') && project.getProperty('release')
  31. official = project.hasProperty('official') && project.getProperty('official')
  32. }
  33. repositories {
  34. def repository = project.hasProperty('qa') ? 'sonarsource-qa' : 'sonarsource'
  35. maven {
  36. // The environment variables ARTIFACTORY_PRIVATE_USERNAME and ARTIFACTORY_PRIVATE_PASSWORD are used on QA env (Jenkins)
  37. // On local box, please add artifactoryUsername and artifactoryPassword to ~/.gradle/gradle.properties
  38. def artifactoryUsername = System.env.'ARTIFACTORY_PRIVATE_USERNAME' ?: (project.hasProperty('artifactoryUsername') ? project.getProperty('artifactoryUsername') : '')
  39. def artifactoryPassword = System.env.'ARTIFACTORY_PRIVATE_PASSWORD' ?: (project.hasProperty('artifactoryPassword') ? project.getProperty('artifactoryPassword') : '')
  40. if (artifactoryUsername && artifactoryPassword) {
  41. credentials {
  42. username artifactoryUsername
  43. password artifactoryPassword
  44. }
  45. } else {
  46. // Workaround for artifactory
  47. // https://www.jfrog.com/jira/browse/RTFACT-13797
  48. repository = 'public'
  49. }
  50. url "https://repox.jfrog.io/repox/${repository}"
  51. }
  52. }
  53. task allDependencies {
  54. dependsOn 'dependencies'
  55. }
  56. artifactory {
  57. clientConfig.setIncludeEnvVars(true)
  58. clientConfig.setEnvVarsExcludePatterns('*password*,*PASSWORD*,*secret*,*MAVEN_CMD_LINE_ARGS*,sun.java.command,*token*,*TOKEN*,*LOGIN*,*login*,*key*,*KEY*,*signing*')
  59. contextUrl = System.getenv('ARTIFACTORY_URL')
  60. publish {
  61. repository {
  62. repoKey = System.getenv('ARTIFACTORY_DEPLOY_REPO')
  63. username = System.getenv('ARTIFACTORY_DEPLOY_USERNAME') ?: project.properties.artifactoryUsername
  64. password = System.getenv('ARTIFACTORY_DEPLOY_PASSWORD') ?: project.properties.artifactoryPaswword
  65. }
  66. defaults {
  67. properties = [
  68. 'build.name': 'sonar-enterprise',
  69. 'build.number': System.getenv('BUILD_NUMBER'),
  70. 'pr.branch.target': System.getenv('GITHUB_BASE_BRANCH'),
  71. 'pr.number': System.getenv('PULL_REQUEST'),
  72. 'vcs.branch': System.getenv('GITHUB_BRANCH'),
  73. 'vcs.revision': System.getenv('GIT_SHA1'),
  74. 'version': version
  75. ]
  76. publications('mavenJava')
  77. publishPom = true
  78. publishIvy = false
  79. }
  80. }
  81. clientConfig.info.setBuildName('sonar-enterprise')
  82. clientConfig.info.setBuildNumber(System.getenv('BUILD_NUMBER'))
  83. // Define the artifacts to be deployed to https://binaries.sonarsource.com on releases
  84. clientConfig.info.addEnvironmentProperty('ARTIFACTS_TO_PUBLISH',
  85. "${project.group}:sonar-application:zip," +
  86. "com.sonarsource.sonarqube:sonarqube-developer:zip," +
  87. "com.sonarsource.sonarqube:sonarqube-datacenter:zip," +
  88. "com.sonarsource.sonarqube:sonarqube-enterprise:zip")
  89. // The name of this variable is important because it's used by the delivery process when extracting version from Artifactory build info.
  90. clientConfig.info.addEnvironmentProperty('PROJECT_VERSION', "${version}")
  91. }
  92. }
  93. apply plugin: 'org.sonarqube'
  94. sonarqube {
  95. properties {
  96. property 'sonar.projectName', projectTitle
  97. property 'sonar.projectVersion', "${versionInSources}-SNAPSHOT"
  98. property 'sonar.buildString', version
  99. }
  100. }
  101. tasks.named('wrapper') {
  102. distributionType = Wrapper.DistributionType.ALL
  103. }
  104. subprojects {
  105. apply plugin: 'com.github.hierynomus.license'
  106. apply plugin: 'io.spring.dependency-management'
  107. apply plugin: 'jacoco'
  108. apply plugin: 'java'
  109. apply plugin: 'idea'
  110. apply plugin: 'signing'
  111. // do not deploy to Artifactory by default
  112. artifactoryPublish.skip = true
  113. def testFixtureSrc = 'src/testFixtures'
  114. if (file(testFixtureSrc).exists()) {
  115. apply plugin: 'java-test-fixtures'
  116. }
  117. ext {
  118. protobufVersion = '3.19.4'
  119. // define a method which can be called by project to change Java version to compile to
  120. configureCompileJavaToVersion = { javaVersion ->
  121. if ( javaVersion != 11 & javaVersion != 8) {
  122. throw new InvalidUserDataException("Only Java 8 and 11 are supported")
  123. }
  124. if ( javaVersion == 8 ) {
  125. println "Configuring project ${project.name} to compile to Java ${javaVersion}"
  126. if (!project.hasProperty('skipJava8Checks')) {
  127. task ensureDependenciesRunOnJava8(dependsOn: [configurations.compileClasspath]) {
  128. ext.readJavaMajorVersion = { classFile ->
  129. classFile.withDataInputStream({ d ->
  130. if (d.skip(7) == 7) {
  131. // read the version of the class file
  132. d.read()
  133. } else {
  134. throw new GradleException("Could not read major version from $classFile")
  135. }
  136. })
  137. }
  138. doLast {
  139. [configurations.compileClasspath].each { config ->
  140. config.resolvedConfiguration.files
  141. .findAll({ f -> f.name.endsWith("jar") })
  142. .each { jarFile ->
  143. def onlyJava8 = true
  144. zipTree(jarFile)
  145. .matching({
  146. include "**/*.class"
  147. // multi-release jar files were introduced with Java 9 => contains only classes targeting Java 9+
  148. exclude "META-INF/versions/**"
  149. // ignore module-info existing in some archives for Java 9 forward compatibility
  150. exclude "module-info.class"
  151. })
  152. .files
  153. .each { classFile ->
  154. int javaMajorVersion = readJavaMajorVersion(classFile)
  155. if (javaMajorVersion > 52) {
  156. println "$classFile has been compiled to a more recent version of Java than 8 (java8=52, java11=55, actual=$javaMajorVersion)"
  157. onlyJava8 = false
  158. }
  159. }
  160. if (!onlyJava8) {
  161. throw new GradleException("Dependency ${jarFile} in configuration ${config.name} contains class file(s) compiled to a Java version > Java 8 (see logs for details)")
  162. }
  163. }
  164. }
  165. }
  166. }
  167. compileJava.dependsOn ensureDependenciesRunOnJava8
  168. }
  169. }
  170. sourceCompatibility = javaVersion
  171. targetCompatibility = javaVersion
  172. tasks.withType(JavaCompile) {
  173. options.compilerArgs.addAll(['--release', javaVersion + ''])
  174. options.encoding = 'UTF-8'
  175. }
  176. }
  177. }
  178. configureCompileJavaToVersion 11
  179. sonarqube {
  180. properties {
  181. property 'sonar.moduleKey', project.group + ':' + project.name
  182. }
  183. }
  184. // Central place for definition dependency versions and exclusions.
  185. dependencyManagement {
  186. dependencies {
  187. // bundled plugin list -- keep it alphabetically ordered
  188. dependency 'com.sonarsource.abap:sonar-abap-plugin:3.10.0.3628'
  189. dependency 'com.sonarsource.cobol:sonar-cobol-plugin:4.6.2.4876'
  190. dependency 'com.sonarsource.cpp:sonar-cfamily-plugin:6.30.0.42324'
  191. dependency 'com.sonarsource.pli:sonar-pli-plugin:1.11.1.2727'
  192. dependency 'com.sonarsource.plsql:sonar-plsql-plugin:3.7.0.4372'
  193. dependency 'com.sonarsource.plugins.vb:sonar-vb-plugin:2.8.0.3021'
  194. dependency 'com.sonarsource.rpg:sonar-rpg-plugin:3.2.0.3034'
  195. dependency 'com.sonarsource.security:sonar-security-csharp-frontend-plugin:9.3.0.14923'
  196. dependency 'com.sonarsource.security:sonar-security-java-frontend-plugin:9.3.0.14923'
  197. dependency 'com.sonarsource.security:sonar-security-php-frontend-plugin:9.3.0.14923'
  198. dependency 'com.sonarsource.security:sonar-security-plugin:9.3.0.14923'
  199. dependency 'com.sonarsource.security:sonar-security-python-frontend-plugin:9.3.0.14923'
  200. dependency 'com.sonarsource.security:sonar-security-js-frontend-plugin:9.3.0.14923'
  201. dependency 'com.sonarsource.slang:sonar-apex-plugin:1.9.0.3429'
  202. dependency 'com.sonarsource.swift:sonar-swift-plugin:4.5.0.5305'
  203. dependency 'com.sonarsource.tsql:sonar-tsql-plugin:1.6.0.4844'
  204. dependency 'org.sonarsource.config:sonar-config-plugin:1.2.0.267'
  205. dependency 'org.sonarsource.dotnet:sonar-csharp-plugin:8.34.0.42011'
  206. dependency 'org.sonarsource.dotnet:sonar-vbnet-plugin:8.34.0.42011'
  207. dependency 'org.sonarsource.flex:sonar-flex-plugin:2.7.0.2865'
  208. dependency 'org.sonarsource.html:sonar-html-plugin:3.6.0.3106'
  209. dependency 'org.sonarsource.jacoco:sonar-jacoco-plugin:1.1.1.1157'
  210. dependency 'org.sonarsource.java:sonar-java-plugin:7.9.0.28969'
  211. dependency 'org.sonarsource.javascript:sonar-javascript-plugin:8.8.0.17228'
  212. dependency 'org.sonarsource.php:sonar-php-plugin:3.22.1.8626'
  213. dependency 'org.sonarsource.python:sonar-python-plugin:3.9.0.9230'
  214. dependency 'org.sonarsource.slang:sonar-go-plugin:1.9.0.3429'
  215. dependency 'org.sonarsource.kotlin:sonar-kotlin-plugin:2.9.0.1147'
  216. dependency 'org.sonarsource.slang:sonar-ruby-plugin:1.9.0.3429'
  217. dependency 'org.sonarsource.slang:sonar-scala-plugin:1.9.0.3429'
  218. dependency 'org.sonarsource.xml:sonar-xml-plugin:2.5.0.3376'
  219. dependency 'org.sonarsource.iac:sonar-iac-plugin:1.5.0.1600'
  220. dependency 'org.sonarsource.text:sonar-text-plugin:1.0.0.120'
  221. // please keep this list alphabetically ordered
  222. dependencySet(group: 'ch.qos.logback', version: '1.2.9') {
  223. entry 'logback-access'
  224. entry 'logback-classic'
  225. entry 'logback-core'
  226. }
  227. dependency('commons-beanutils:commons-beanutils:1.9.4') {
  228. exclude 'commons-logging:commons-logging'
  229. }
  230. dependency 'commons-codec:commons-codec:1.15'
  231. dependency 'commons-dbutils:commons-dbutils:1.7'
  232. dependency 'commons-io:commons-io:2.11.0'
  233. dependency 'commons-lang:commons-lang:2.6'
  234. imports { mavenBom 'com.fasterxml.jackson:jackson-bom:2.13.1' }
  235. dependencySet(group: 'com.fasterxml.jackson.dataformat', version: '2.13.1') {
  236. entry 'jackson-dataformat-cbor'
  237. entry 'jackson-dataformat-smile'
  238. entry 'jackson-dataformat-yaml'
  239. }
  240. dependency 'com.eclipsesource.minimal-json:minimal-json:0.9.5'
  241. dependencySet(group: 'com.github.scribejava', version: '6.9.0') {
  242. entry 'scribejava-apis'
  243. entry 'scribejava-core'
  244. }
  245. dependency 'com.github.everit-org.json-schema:org.everit.json.schema:1.14.0'
  246. // This project is no longer maintained and was forked
  247. // by https://github.com/java-diff-utils/java-diff-utils
  248. // (io.github.java-diff-utils:java-diff-utils).
  249. dependency 'com.googlecode.java-diff-utils:diffutils:1.3.0'
  250. dependency('com.googlecode.json-simple:json-simple:1.1.1') {
  251. exclude 'junit:junit'
  252. }
  253. dependency 'io.prometheus:simpleclient:0.14.1'
  254. dependency 'io.prometheus:simpleclient_common:0.14.1'
  255. dependency 'io.prometheus:simpleclient_servlet:0.14.1'
  256. dependency 'com.google.code.findbugs:jsr305:3.0.2'
  257. dependency 'com.google.code.gson:gson:2.8.9'
  258. dependency('com.google.guava:guava:31.0.1-jre') {
  259. exclude 'com.google.errorprone:error_prone_annotations'
  260. exclude 'com.google.guava:listenablefuture'
  261. exclude 'com.google.j2objc:j2objc-annotations'
  262. exclude 'org.checkerframework:checker-qual'
  263. exclude 'org.codehaus.mojo:animal-sniffer-annotations'
  264. }
  265. dependency "com.google.protobuf:protobuf-java:${protobufVersion}"
  266. dependency 'com.h2database:h2:2.1.210'
  267. dependencySet(group: 'com.hazelcast', version: '4.2.4') {
  268. entry 'hazelcast'
  269. }
  270. dependency 'com.hazelcast:hazelcast-kubernetes:2.2.3'
  271. // Documentation must be updated if mssql-jdbc is updated: https://github.com/SonarSource/sonarqube/commit/03e4773ebf6cba854cdcf57a600095f65f4f53e7
  272. dependency 'com.microsoft.sqlserver:mssql-jdbc:9.4.1.jre11'
  273. dependency 'com.oracle.database.jdbc:ojdbc8:21.4.0.0.1'
  274. dependency 'org.aspectj:aspectjtools:1.9.7'
  275. // upgrade okhttp3 dependency kotlin to get rid of not exploitable CVE-2020-29582
  276. dependency 'org.jetbrains.kotlin:kotlin-stdlib-common:1.6.10'
  277. dependency 'org.jetbrains.kotlin:kotlin-stdlib:1.6.10'
  278. dependencySet(group: 'com.squareup.okhttp3', version: '4.9.3') {
  279. entry 'okhttp'
  280. entry 'mockwebserver'
  281. }
  282. dependency 'org.json:json:20211205'
  283. dependency 'com.tngtech.java:junit-dataprovider:1.13.1'
  284. dependency 'info.picocli:picocli:3.6.1'
  285. dependencySet(group: 'io.jsonwebtoken', version: '0.11.2') {
  286. entry 'jjwt-api'
  287. entry 'jjwt-impl'
  288. entry 'jjwt-jackson'
  289. }
  290. dependency 'com.auth0:java-jwt:3.18.3'
  291. dependency 'io.netty:netty-all:4.1.73.Final'
  292. dependency 'com.sun.mail:javax.mail:1.6.2'
  293. dependency 'javax.annotation:javax.annotation-api:1.3.2'
  294. dependency 'javax.inject:javax.inject:1'
  295. dependency 'javax.servlet:javax.servlet-api:3.1.0'
  296. dependency 'javax.xml.bind:jaxb-api:2.3.1'
  297. dependency 'junit:junit:4.13.2'
  298. dependency 'org.junit.jupiter:junit-jupiter-api:5.8.2'
  299. dependency 'org.xmlunit:xmlunit-core:2.9.0'
  300. dependency 'org.xmlunit:xmlunit-matchers:2.9.0'
  301. dependency 'net.jpountz.lz4:lz4:1.3.0'
  302. dependency 'net.lightbody.bmp:littleproxy:1.1.0-beta-bmp-17'
  303. dependency 'org.awaitility:awaitility:4.1.1'
  304. dependency 'org.apache.commons:commons-csv:1.9.0'
  305. dependency 'org.apache.commons:commons-email:1.5'
  306. dependency 'org.apache.commons:commons-dbcp2:2.9.0'
  307. dependency('org.apache.httpcomponents:httpclient:4.5.13'){
  308. exclude 'commons-logging:commons-logging'
  309. }
  310. // Be aware that Log4j is used by Elasticsearch client
  311. dependencySet(group: 'org.apache.logging.log4j', version: '2.17.1') {
  312. entry 'log4j-core'
  313. entry 'log4j-api'
  314. entry 'log4j-to-slf4j'
  315. }
  316. dependencySet(group: 'org.apache.tomcat.embed', version: '8.5.73') {
  317. entry 'tomcat-embed-core'
  318. entry('tomcat-embed-jasper') {
  319. exclude 'org.eclipse.jdt.core.compiler:ecj'
  320. }
  321. }
  322. dependency 'org.assertj:assertj-core:3.22.0'
  323. dependency 'org.assertj:assertj-guava:3.4.0'
  324. dependency('org.codehaus.sonar:sonar-channel:4.2') {
  325. exclude 'org.slf4j:slf4j-api'
  326. }
  327. dependency 'org.codehaus.sonar:sonar-classloader:1.0'
  328. dependency 'com.fasterxml.staxmate:staxmate:2.4.0'
  329. dependencySet(group: 'org.eclipse.jetty', version: '9.4.6.v20170531') {
  330. entry 'jetty-proxy'
  331. entry 'jetty-server'
  332. entry 'jetty-servlet'
  333. }
  334. dependency('org.elasticsearch.client:elasticsearch-rest-high-level-client:7.17.1') {
  335. exclude 'org.apache.logging.log4j:log4j-core'
  336. }
  337. dependency 'org.elasticsearch.plugin:transport-netty4-client:7.17.1'
  338. dependency 'org.elasticsearch:mocksocket:1.2'
  339. dependency 'org.codelibs.elasticsearch.module:analysis-common:7.17.1'
  340. dependency 'org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r'
  341. dependency 'org.tmatesoft.svnkit:svnkit:1.10.4'
  342. dependency 'org.hamcrest:hamcrest-all:1.3'
  343. dependency 'org.jsoup:jsoup:1.14.3'
  344. dependency 'org.mindrot:jbcrypt:0.4'
  345. dependency('org.mockito:mockito-core:3.12.4') {
  346. exclude 'org.hamcrest:hamcrest-core'
  347. }
  348. dependency 'org.mybatis:mybatis:3.5.9'
  349. dependency 'org.nanohttpd:nanohttpd:2.3.1'
  350. dependencySet(group: 'org.slf4j', version: '1.7.30') {
  351. entry 'jcl-over-slf4j'
  352. entry 'jul-to-slf4j'
  353. entry 'log4j-over-slf4j'
  354. entry 'slf4j-api'
  355. }
  356. dependency 'org.postgresql:postgresql:42.3.3'
  357. dependency 'org.reflections:reflections:0.10.2'
  358. dependency 'org.simpleframework:simple:4.1.21'
  359. dependency 'org.sonarsource.orchestrator:sonar-orchestrator:3.37.0.87'
  360. dependency 'org.sonarsource.update-center:sonar-update-center-common:1.23.0.723'
  361. dependency('org.springframework:spring-context:5.3.15') {
  362. exclude 'commons-logging:commons-logging'
  363. }
  364. dependency 'org.subethamail:subethasmtp:3.1.7'
  365. dependency 'org.yaml:snakeyaml:1.30'
  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. encoding = 'UTF-8'
  488. mapping {
  489. java = 'SLASHSTAR_STYLE'
  490. js = 'SLASHSTAR_STYLE'
  491. ts = 'SLASHSTAR_STYLE'
  492. tsx = 'SLASHSTAR_STYLE'
  493. css = 'SLASHSTAR_STYLE'
  494. }
  495. includes(['**/*.java', '**/*.js', '**/*.ts', '**/*.tsx', '**/*.css'])
  496. }
  497. tasks.withType(GenerateModuleMetadata) {
  498. enabled = false
  499. }
  500. publishing {
  501. publications {
  502. mavenJava(MavenPublication) {
  503. pom {
  504. name = 'SonarQube'
  505. description = project.description
  506. url = 'http://www.sonarqube.org/'
  507. organization {
  508. name = 'SonarSource'
  509. url = 'http://www.sonarsource.com'
  510. }
  511. licenses {
  512. license {
  513. name = 'GNU LGPL 3'
  514. url = 'http://www.gnu.org/licenses/lgpl.txt'
  515. distribution = 'repo'
  516. }
  517. }
  518. scm {
  519. url = 'https://github.com/SonarSource/sonarqube'
  520. }
  521. developers {
  522. developer {
  523. id = 'sonarsource-team'
  524. name = 'SonarSource Team'
  525. }
  526. }
  527. }
  528. }
  529. }
  530. }
  531. if (System.getenv('GITHUB_BRANCH') == "branch-nightly-build") {
  532. tasks.withType(Test) {
  533. configurations {
  534. utMonitoring
  535. }
  536. dependencies {
  537. testCompile project(":ut-monitoring")
  538. utMonitoring 'org.aspectj:aspectjweaver:1.9.7'
  539. }
  540. doFirst {
  541. ext {
  542. aspectJWeaver = configurations.utMonitoring.resolvedConfiguration.resolvedArtifacts.find { it.name == 'aspectjweaver' }
  543. }
  544. jvmArgs "-javaagent:${aspectJWeaver.file}"
  545. }
  546. }
  547. }
  548. signing {
  549. def signingKeyId = findProperty("signingKeyId")
  550. def signingKey = findProperty("signingKey")
  551. def signingPassword = findProperty("signingPassword")
  552. useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
  553. required {
  554. def branch = System.getenv()["GITHUB_BRANCH"]
  555. return (branch in ['master', 'dogfood-on-next'] || branch ==~ 'branch-[\\d.]+') &&
  556. gradle.taskGraph.hasTask(":artifactoryPublish")
  557. }
  558. sign publishing.publications
  559. }
  560. tasks.withType(Sign) {
  561. onlyIf {
  562. def branch = System.getenv()["GITHUB_BRANCH"]
  563. return !artifactoryPublish.skip &&
  564. (branch in ['master', 'dogfood-on-next'] || branch ==~ 'branch-[\\d.]+') &&
  565. gradle.taskGraph.hasTask(":artifactoryPublish")
  566. }
  567. }
  568. }
  569. gradle.projectsEvaluated { gradle ->
  570. // yarn_run tasks can't all run in parallel without random issues
  571. // this script ensure all yarn_run tasks run sequentially
  572. def yarnRunTasks = allprojects.findResults { it -> it.tasks.findByName('yarn_run') }
  573. yarnRunTasks.drop(1).eachWithIndex { it, i -> it.mustRunAfter(yarnRunTasks[0..i]) }
  574. }
  575. ext.osAdaptiveCommand = { commands ->
  576. def newCommands = []
  577. if (System.properties['os.name'].toLowerCase().contains('windows')) {
  578. newCommands = ['cmd', '/c']
  579. }
  580. newCommands.addAll(commands)
  581. return newCommands
  582. }
  583. tasks.named('sonarqube') {
  584. long taskStart
  585. doFirst {
  586. taskStart = System.currentTimeMillis()
  587. }
  588. doLast {
  589. long taskDuration = System.currentTimeMillis() - taskStart
  590. File outputFile = new File("/tmp/analysis-monitoring.log")
  591. outputFile.append(JsonOutput.toJson([category: "Analysis", suite: "Standalone", operation: "total", duration: taskDuration]) + '\n')
  592. }
  593. }