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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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.3'
  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.10.0.3628'
  222. dependency 'com.sonarsource.cobol:sonar-cobol-plugin:4.6.2.4876'
  223. dependency 'com.sonarsource.cpp:sonar-cfamily-plugin:6.30.0.42324'
  224. dependency 'com.sonarsource.pli:sonar-pli-plugin:1.11.1.2727'
  225. dependency 'com.sonarsource.plsql:sonar-plsql-plugin:3.7.0.4372'
  226. dependency 'com.sonarsource.plugins.vb:sonar-vb-plugin:2.8.0.3021'
  227. dependency 'com.sonarsource.rpg:sonar-rpg-plugin:3.2.0.3034'
  228. dependency 'com.sonarsource.security:sonar-security-csharp-frontend-plugin:9.3.0.14923'
  229. dependency 'com.sonarsource.security:sonar-security-java-frontend-plugin:9.3.0.14923'
  230. dependency 'com.sonarsource.security:sonar-security-php-frontend-plugin:9.3.0.14923'
  231. dependency 'com.sonarsource.security:sonar-security-plugin:9.3.0.14923'
  232. dependency 'com.sonarsource.security:sonar-security-python-frontend-plugin:9.3.0.14923'
  233. dependency 'com.sonarsource.security:sonar-security-js-frontend-plugin:9.3.0.14923'
  234. dependency 'com.sonarsource.slang:sonar-apex-plugin:1.9.0.3429'
  235. dependency 'com.sonarsource.swift:sonar-swift-plugin:4.5.0.5305'
  236. dependency 'com.sonarsource.tsql:sonar-tsql-plugin:1.6.0.4844'
  237. dependency 'org.sonarsource.config:sonar-config-plugin:1.2.0.267'
  238. dependency 'org.sonarsource.dotnet:sonar-csharp-plugin:8.34.0.42011'
  239. dependency 'org.sonarsource.dotnet:sonar-vbnet-plugin:8.34.0.42011'
  240. dependency 'org.sonarsource.flex:sonar-flex-plugin:2.7.0.2865'
  241. dependency 'org.sonarsource.html:sonar-html-plugin:3.6.0.3106'
  242. dependency 'org.sonarsource.jacoco:sonar-jacoco-plugin:1.1.1.1157'
  243. dependency 'org.sonarsource.java:sonar-java-plugin:7.7.0.28547'
  244. dependency 'org.sonarsource.javascript:sonar-javascript-plugin:8.8.0.17228'
  245. dependency 'org.sonarsource.php:sonar-php-plugin:3.22.1.8626'
  246. dependency 'org.sonarsource.python:sonar-python-plugin:3.9.0.9230'
  247. dependency 'org.sonarsource.slang:sonar-go-plugin:1.9.0.3429'
  248. dependency 'org.sonarsource.kotlin:sonar-kotlin-plugin:2.9.0.1147'
  249. dependency 'org.sonarsource.slang:sonar-ruby-plugin:1.9.0.3429'
  250. dependency 'org.sonarsource.slang:sonar-scala-plugin:1.9.0.3429'
  251. dependency 'org.sonarsource.xml:sonar-xml-plugin:2.5.0.3376'
  252. dependency 'org.sonarsource.iac:sonar-iac-plugin:1.5.0.1600'
  253. dependency 'org.sonarsource.text:sonar-text-plugin:1.0.0.120'
  254. // please keep this list alphabetically ordered
  255. dependencySet(group: 'ch.qos.logback', version: '1.2.9') {
  256. entry 'logback-access'
  257. entry 'logback-classic'
  258. entry 'logback-core'
  259. }
  260. dependency('commons-beanutils:commons-beanutils:1.8.3') {
  261. exclude 'commons-logging:commons-logging'
  262. }
  263. dependency 'commons-codec:commons-codec:1.15'
  264. dependency 'commons-dbutils:commons-dbutils:1.7'
  265. dependency 'commons-io:commons-io:2.11.0'
  266. dependency 'commons-lang:commons-lang:2.6'
  267. imports { mavenBom 'com.fasterxml.jackson:jackson-bom:2.11.4' }
  268. dependencySet(group: 'com.fasterxml.jackson.dataformat', version: '2.11.4') {
  269. entry 'jackson-dataformat-cbor'
  270. entry 'jackson-dataformat-smile'
  271. entry 'jackson-dataformat-yaml'
  272. }
  273. dependency 'com.eclipsesource.minimal-json:minimal-json:0.9.5'
  274. dependencySet(group: 'com.github.scribejava', version: '6.9.0') {
  275. entry 'scribejava-apis'
  276. entry 'scribejava-core'
  277. }
  278. dependency 'com.github.everit-org.json-schema:org.everit.json.schema:1.14.0'
  279. // This project is no longer maintained and was forked
  280. // by https://github.com/java-diff-utils/java-diff-utils
  281. // (io.github.java-diff-utils:java-diff-utils).
  282. dependency 'com.googlecode.java-diff-utils:diffutils:1.3.0'
  283. dependency('com.googlecode.json-simple:json-simple:1.1.1') {
  284. exclude 'junit:junit'
  285. }
  286. dependency 'io.prometheus:simpleclient:0.14.1'
  287. dependency 'io.prometheus:simpleclient_common:0.14.1'
  288. dependency 'io.prometheus:simpleclient_servlet:0.14.1'
  289. dependency 'com.google.code.findbugs:jsr305:3.0.2'
  290. dependency 'com.google.code.gson:gson:2.8.9'
  291. dependency('com.google.guava:guava:28.2-jre') {
  292. exclude 'com.google.errorprone:error_prone_annotations'
  293. exclude 'com.google.guava:listenablefuture'
  294. exclude 'com.google.j2objc:j2objc-annotations'
  295. exclude 'org.checkerframework:checker-qual'
  296. exclude 'org.codehaus.mojo:animal-sniffer-annotations'
  297. }
  298. dependency "com.google.protobuf:protobuf-java:${protobufVersion}"
  299. // Do not upgrade H2 to 1.4.200 because of instability: https://github.com/h2database/h2database/issues/2205
  300. dependency 'com.h2database:h2:1.4.199'
  301. dependencySet(group: 'com.hazelcast', version: '4.2.2') {
  302. entry 'hazelcast'
  303. }
  304. dependency 'com.hazelcast:hazelcast-kubernetes:2.2.3'
  305. dependency 'com.ibm.icu:icu4j:3.4.4'
  306. // Documentation must be updated if mssql-jdbc is updated: https://github.com/SonarSource/sonarqube/commit/03e4773ebf6cba854cdcf57a600095f65f4f53e7
  307. dependency 'com.microsoft.sqlserver:mssql-jdbc:9.4.1.jre11'
  308. dependency 'com.oracle.database.jdbc:ojdbc8:21.4.0.0.1'
  309. dependency 'org.aspectj:aspectjtools:1.9.6'
  310. // upgrade okhttp3 dependency kotlin to get rid of not exploitable CVE-2020-29582
  311. dependency 'org.jetbrains.kotlin:kotlin-stdlib-common:1.4.21'
  312. dependency 'org.jetbrains.kotlin:kotlin-stdlib:1.4.21'
  313. dependencySet(group: 'com.squareup.okhttp3', version: '4.9.3') {
  314. entry 'okhttp'
  315. entry 'mockwebserver'
  316. }
  317. dependency 'com.tngtech.java:junit-dataprovider:1.13.1'
  318. dependency 'info.picocli:picocli:3.6.1'
  319. dependencySet(group: 'io.jsonwebtoken', version: '0.11.2') {
  320. entry 'jjwt-api'
  321. entry 'jjwt-impl'
  322. entry 'jjwt-jackson'
  323. }
  324. dependency 'com.auth0:java-jwt:3.18.2'
  325. dependency 'io.netty:netty-all:4.1.70.Final'
  326. dependency 'com.sun.mail:javax.mail:1.5.6'
  327. dependency 'javax.annotation:javax.annotation-api:1.3.2'
  328. dependency 'javax.servlet:javax.servlet-api:3.1.0'
  329. dependency 'javax.xml.bind:jaxb-api:2.3.0'
  330. dependency 'junit:junit:4.13.2'
  331. dependency 'org.junit.jupiter:junit-jupiter-api:5.8.1'
  332. dependency 'org.xmlunit:xmlunit-core:2.8.3'
  333. dependency 'org.xmlunit:xmlunit-matchers:2.8.3'
  334. dependency 'net.jpountz.lz4:lz4:1.3.0'
  335. dependency 'net.lightbody.bmp:littleproxy:1.1.0-beta-bmp-17'
  336. dependency 'org.awaitility:awaitility:4.1.1'
  337. dependency 'org.apache.commons:commons-csv:1.9.0'
  338. dependency 'org.apache.commons:commons-email:1.5'
  339. dependency 'org.apache.commons:commons-dbcp2:2.9.0'
  340. dependency('org.apache.httpcomponents:httpclient:4.5.13'){
  341. exclude 'commons-logging:commons-logging'
  342. }
  343. // Be aware that Log4j is used by Elasticsearch client
  344. dependencySet(group: 'org.apache.logging.log4j', version: '2.17.1') {
  345. entry 'log4j-core'
  346. entry 'log4j-api'
  347. entry 'log4j-to-slf4j'
  348. }
  349. dependencySet(group: 'org.apache.tomcat.embed', version: '8.5.73') {
  350. entry 'tomcat-embed-core'
  351. entry('tomcat-embed-jasper') {
  352. exclude 'org.eclipse.jdt.core.compiler:ecj'
  353. }
  354. }
  355. dependency 'org.assertj:assertj-core:3.21.0'
  356. dependency 'org.assertj:assertj-guava:3.4.0'
  357. dependency('org.codehaus.sonar:sonar-channel:4.2') {
  358. exclude 'org.slf4j:slf4j-api'
  359. }
  360. dependency 'org.codehaus.sonar:sonar-classloader:1.0'
  361. dependency 'com.fasterxml.staxmate:staxmate:2.4.0'
  362. dependencySet(group: 'org.eclipse.jetty', version: '9.4.6.v20170531') {
  363. entry 'jetty-proxy'
  364. entry 'jetty-server'
  365. entry 'jetty-servlet'
  366. }
  367. dependency('org.elasticsearch.client:elasticsearch-rest-high-level-client:7.16.0') {
  368. exclude 'org.apache.logging.log4j:log4j-core'
  369. }
  370. dependency 'org.elasticsearch.plugin:transport-netty4-client:7.16.0'
  371. dependency 'org.elasticsearch:mocksocket:1.0'
  372. dependency 'org.codelibs.elasticsearch.module:analysis-common:7.16.0'
  373. dependency 'org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r'
  374. dependency 'org.tmatesoft.svnkit:svnkit:1.10.3'
  375. dependency 'org.hamcrest:hamcrest-all:1.3'
  376. dependency 'org.jsoup:jsoup:1.14.3'
  377. dependency 'org.mindrot:jbcrypt:0.4'
  378. dependency('org.mockito:mockito-core:3.12.4') {
  379. exclude 'org.hamcrest:hamcrest-core'
  380. }
  381. dependency 'org.mybatis:mybatis:3.5.7'
  382. dependency 'org.nanohttpd:nanohttpd:2.3.1'
  383. dependency 'org.picocontainer:picocontainer:2.15'
  384. dependencySet(group: 'org.slf4j', version: '1.7.30') {
  385. entry 'jcl-over-slf4j'
  386. entry 'jul-to-slf4j'
  387. entry 'log4j-over-slf4j'
  388. entry 'slf4j-api'
  389. }
  390. dependency 'org.postgresql:postgresql:42.3.1'
  391. dependency 'org.reflections:reflections:0.10.2'
  392. dependency 'org.simpleframework:simple:4.1.21'
  393. dependency 'org.sonarsource.orchestrator:sonar-orchestrator:3.36.0.63'
  394. dependency 'org.sonarsource.update-center:sonar-update-center-common:1.23.0.723'
  395. dependency 'org.subethamail:subethasmtp:3.1.7'
  396. dependency 'org.yaml:snakeyaml:1.26'
  397. dependency 'xml-apis:xml-apis:1.4.01'
  398. // please keep this list alphabetically ordered
  399. }
  400. }
  401. // global exclusions
  402. configurations.all {
  403. // do not conflict with com.sun.mail:javax.mail
  404. exclude group: 'javax.mail', module: 'mail'
  405. }
  406. tasks.withType(Javadoc) {
  407. options.addStringOption('Xdoclint:none', '-quiet')
  408. options.encoding = 'UTF-8'
  409. doFirst {
  410. options.addBooleanOption('-no-module-directories', true)
  411. }
  412. title = project.name + ' ' + versionWithoutBuildNumber
  413. }
  414. task sourcesJar(type: Jar, dependsOn: classes) {
  415. archiveClassifier = 'sources'
  416. from sourceSets.main.allSource
  417. }
  418. task javadocJar(type: Jar, dependsOn: javadoc) {
  419. archiveClassifier = 'javadoc'
  420. from javadoc.destinationDir
  421. }
  422. // generate code before opening project in IDE (Eclipse or Intellij)
  423. task ide() {
  424. // empty by default. Dependencies are added to the task
  425. // when needed (see protobuf modules for example)
  426. }
  427. jacocoTestReport {
  428. reports {
  429. xml.required = true
  430. csv.required = false
  431. html.required = false
  432. }
  433. }
  434. normalization {
  435. runtimeClasspath {
  436. // Following classpath resources contain volatile data that changes in each CI build (build number, commit id, time),
  437. // so we exclude them from calculation of build cache key of test tasks:
  438. ignore 'META-INF/MANIFEST.MF'
  439. ignore 'sonar-api-version.txt'
  440. ignore 'sq-version.txt'
  441. }
  442. }
  443. ext.failedTests = []
  444. test {
  445. jvmArgs '-Dfile.encoding=UTF8'
  446. maxHeapSize = '1G'
  447. systemProperty 'java.awt.headless', true
  448. testLogging {
  449. events "skipped", "failed" // verbose log for failed and skipped tests (by default the name of the tests are not logged)
  450. exceptionFormat 'full' // log the full stack trace (default is the 1st line of the stack trace)
  451. }
  452. jacoco {
  453. enabled = true // do not disable recording of code coverage, so that remote Gradle cache entry can be used locally
  454. includes = ['com.sonar.*', 'com.sonarsource.*', 'org.sonar.*', 'org.sonarqube.*', 'org.sonarsource.*']
  455. }
  456. if (project.hasProperty('maxParallelTests')) {
  457. maxParallelForks = project.maxParallelTests as int
  458. }
  459. if (project.hasProperty('parallelTests')) {
  460. // See https://guides.gradle.org/performance/#parallel_test_execution
  461. maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
  462. }
  463. afterTest { descriptor, result ->
  464. if (result.resultType == TestResult.ResultType.FAILURE) {
  465. String failedTest = " ${descriptor.className} > ${descriptor.name}"
  466. failedTests << failedTest
  467. }
  468. }
  469. }
  470. gradle.buildFinished {
  471. if (!failedTests.empty) {
  472. println "\nFailed tests:"
  473. failedTests.each { failedTest ->
  474. println failedTest
  475. }
  476. println ""
  477. }
  478. }
  479. def protoMainSrc = 'src/main/protobuf'
  480. def protoTestSrc = 'src/test/protobuf'
  481. if (file(protoMainSrc).exists() || file(protoTestSrc).exists()) {
  482. // protobuf must be applied after java
  483. apply plugin: 'com.google.protobuf'
  484. sourceSets.main.proto.srcDir protoMainSrc // in addition to the default 'src/main/proto'
  485. sourceSets.test.proto.srcDir protoTestSrc // in addition to the default 'src/test/proto'
  486. protobuf {
  487. protoc {
  488. artifact = "com.google.protobuf:protoc:${protobufVersion}"
  489. }
  490. }
  491. jar {
  492. exclude('**/*.proto')
  493. }
  494. idea {
  495. module {
  496. sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java")
  497. testSourceDirs += file("${protobuf.generatedFilesBaseDir}/test/java")
  498. generatedSourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java")
  499. generatedSourceDirs += file("${protobuf.generatedFilesBaseDir}/test/java")
  500. }
  501. }
  502. ide.dependsOn(['generateProto', 'generateTestProto'])
  503. }
  504. if (official) {
  505. jar {
  506. // do not break incremental build on non official versions
  507. manifest {
  508. attributes(
  509. 'Version': "${version}",
  510. 'Implementation-Build': System.getenv('GIT_SHA1'),
  511. 'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
  512. )
  513. }
  514. }
  515. }
  516. license {
  517. header = rootProject.file('HEADER')
  518. strictCheck true
  519. encoding = 'UTF-8'
  520. mapping {
  521. java = 'SLASHSTAR_STYLE'
  522. js = 'SLASHSTAR_STYLE'
  523. ts = 'SLASHSTAR_STYLE'
  524. tsx = 'SLASHSTAR_STYLE'
  525. css = 'SLASHSTAR_STYLE'
  526. }
  527. includes(['**/*.java', '**/*.js', '**/*.ts', '**/*.tsx', '**/*.css'])
  528. }
  529. tasks.withType(GenerateModuleMetadata) {
  530. enabled = false
  531. }
  532. publishing {
  533. publications {
  534. mavenJava(MavenPublication) {
  535. pom {
  536. name = 'SonarQube'
  537. description = project.description
  538. url = 'http://www.sonarqube.org/'
  539. organization {
  540. name = 'SonarSource'
  541. url = 'http://www.sonarsource.com'
  542. }
  543. licenses {
  544. license {
  545. name = 'GNU LGPL 3'
  546. url = 'http://www.gnu.org/licenses/lgpl.txt'
  547. distribution = 'repo'
  548. }
  549. }
  550. scm {
  551. url = 'https://github.com/SonarSource/sonarqube'
  552. }
  553. developers {
  554. developer {
  555. id = 'sonarsource-team'
  556. name = 'SonarSource Team'
  557. }
  558. }
  559. }
  560. }
  561. }
  562. }
  563. if (System.getenv('GITHUB_BRANCH') == "branch-nightly-build") {
  564. tasks.withType(Test) {
  565. configurations {
  566. utMonitoring
  567. }
  568. dependencies {
  569. testCompile project(":ut-monitoring")
  570. utMonitoring 'org.aspectj:aspectjweaver:1.9.6'
  571. }
  572. doFirst {
  573. ext {
  574. aspectJWeaver = configurations.utMonitoring.resolvedConfiguration.resolvedArtifacts.find { it.name == 'aspectjweaver' }
  575. }
  576. jvmArgs "-javaagent:${aspectJWeaver.file}"
  577. }
  578. }
  579. }
  580. signing {
  581. def signingKeyId = findProperty("signingKeyId")
  582. def signingKey = findProperty("signingKey")
  583. def signingPassword = findProperty("signingPassword")
  584. useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
  585. required {
  586. def branch = System.getenv()["GITHUB_BRANCH"]
  587. return (branch in ['master', 'dogfood-on-next'] || branch ==~ 'branch-[\\d.]+') &&
  588. gradle.taskGraph.hasTask(":artifactoryPublish")
  589. }
  590. sign publishing.publications
  591. }
  592. tasks.withType(Sign) {
  593. onlyIf {
  594. def branch = System.getenv()["GITHUB_BRANCH"]
  595. return !artifactoryPublish.skip &&
  596. (branch in ['master', 'dogfood-on-next'] || branch ==~ 'branch-[\\d.]+') &&
  597. gradle.taskGraph.hasTask(":artifactoryPublish")
  598. }
  599. }
  600. }
  601. // https://github.com/ben-manes/gradle-versions-plugin
  602. apply plugin: 'com.github.ben-manes.versions'
  603. dependencyUpdates {
  604. rejectVersionIf {
  605. // Exclude dev versions from the list of dependency upgrades, for
  606. // example to replace:
  607. // org.slf4j:log4j-over-slf4j [1.7.25 -> 1.8.0-beta4]
  608. // by
  609. // org.slf4j:log4j-over-slf4j [1.7.25 -> 1.7.26]
  610. boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm', 'preview', 'jre12'].any { qualifier ->
  611. it.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
  612. }
  613. // Exclude upgrades on new major versions :
  614. // com.hazelcast:hazelcast [3.12.3 -> 4.0.0]
  615. rejected |= !it.candidate.version.substring(0, 2).equals(it.currentVersion.substring(0, 2))
  616. rejected
  617. }
  618. }
  619. gradle.projectsEvaluated { gradle ->
  620. // Execute dependencyCheckAggregate prerequisites before the actual check
  621. allprojects
  622. .findResults { it -> it.tasks.findByName('dependencyCheckAggregate_prerequisites') }
  623. .each { t -> dependencyCheckAggregate.dependsOn(t) }
  624. // yarn_run tasks can't all run in parallel without random issues
  625. // this script ensure all yarn_run tasks run sequentially
  626. def yarnRunTasks = allprojects.findResults { it -> it.tasks.findByName('yarn_run') }
  627. yarnRunTasks.drop(1).eachWithIndex { it, i -> it.mustRunAfter(yarnRunTasks[0..i]) }
  628. }
  629. ext.osAdaptiveCommand = { commands ->
  630. def newCommands = []
  631. if (System.properties['os.name'].toLowerCase().contains('windows')) {
  632. newCommands = ['cmd', '/c']
  633. }
  634. newCommands.addAll(commands)
  635. return newCommands
  636. }
  637. tasks.named('sonarqube') {
  638. long taskStart
  639. doFirst {
  640. taskStart = System.currentTimeMillis()
  641. }
  642. doLast {
  643. long taskDuration = System.currentTimeMillis() - taskStart
  644. File outputFile = new File("/tmp/analysis-monitoring.log")
  645. outputFile.append(JsonOutput.toJson([category: "Analysis", suite: "Standalone", operation: "total", duration: taskDuration]) + '\n')
  646. }
  647. }