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

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