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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  1. buildscript {
  2. repositories {
  3. maven {
  4. url 'https://repox.jfrog.io/repox/plugins.gradle.org/'
  5. }
  6. }
  7. dependencies {
  8. // Ordered alphabeticly to avoid duplication
  9. classpath 'com.github.ben-manes:gradle-versions-plugin:0.21.0'
  10. classpath 'com.github.jengelman.gradle.plugins:shadow:5.0.0'
  11. classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.8'
  12. classpath 'com.moowork.gradle:gradle-node-plugin:1.2.0'
  13. classpath 'gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.14.0'
  14. classpath 'io.spring.gradle:dependency-management-plugin:1.0.4.RELEASE'
  15. classpath 'net.rdrei.android.buildtimetracker:gradle-plugin:0.11.0'
  16. classpath 'org.jfrog.buildinfo:build-info-extractor-gradle:4.7.5'
  17. classpath "org.owasp:dependency-check-gradle:4.0.2"
  18. classpath 'org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.7.1'
  19. }
  20. }
  21. // display a summary of task durations at the end of the build
  22. if (project.hasProperty('time-tracker')) {
  23. apply plugin: 'build-time-tracker'
  24. buildtimetracker {
  25. reporters {
  26. summary {
  27. ordered true
  28. threshold 1000
  29. barstyle 'ascii'
  30. }
  31. }
  32. }
  33. }
  34. // Analyze SonarQube with SonarQube!
  35. ext.versionInSources = version
  36. apply plugin: 'org.sonarqube'
  37. sonarqube {
  38. properties {
  39. property 'sonar.projectName', projectTitle
  40. property 'sonar.projectVersion', versionInSources
  41. property 'sonar.buildString', version
  42. }
  43. }
  44. if (!JavaVersion.current().java11Compatible) {
  45. throw new GradleException("JDK 11+ is required to perform this build. It's currently " + System.getProperty("java.home") + ".")
  46. }
  47. allprojects {
  48. apply plugin: 'com.jfrog.artifactory'
  49. apply plugin: 'maven-publish'
  50. ext.buildNumber = System.getProperty("buildNumber")
  51. ext.versionWithoutBuildNumber = version
  52. // Replaces the version defined in sources, usually x.y-SNAPSHOT, by a version identifying the build.
  53. if (version.endsWith('-SNAPSHOT') && ext.buildNumber != null) {
  54. def versionSuffix = (version.toString().count('.') == 1 ? ".0.${ext.buildNumber}" : ".${ext.buildNumber}")
  55. version = version.replace('-SNAPSHOT', versionSuffix)
  56. }
  57. ext {
  58. release = project.hasProperty('release') && project.getProperty('release')
  59. official = project.hasProperty('official') && project.getProperty('official')
  60. }
  61. repositories {
  62. def repository = project.hasProperty('qa') ? 'sonarsource-qa' : 'sonarsource'
  63. maven {
  64. url "https://repox.jfrog.io/repox/${repository}"
  65. // The environment variables ARTIFACTORY_PRIVATE_USERNAME and ARTIFACTORY_PRIVATE_PASSWORD are used on QA env (Jenkins)
  66. // On local box, please add artifactoryUsername and artifactoryPassword to ~/.gradle/gradle.properties
  67. def artifactoryUsername = System.env.'ARTIFACTORY_PRIVATE_USERNAME' ?: (project.hasProperty('artifactoryUsername') ? project.getProperty('artifactoryUsername') : '')
  68. def artifactoryPassword = System.env.'ARTIFACTORY_PRIVATE_PASSWORD' ?: (project.hasProperty('artifactoryPassword') ? project.getProperty('artifactoryPassword') : '')
  69. if (artifactoryUsername && artifactoryPassword) {
  70. credentials {
  71. username artifactoryUsername
  72. password artifactoryPassword
  73. }
  74. }
  75. }
  76. }
  77. }
  78. subprojects {
  79. apply plugin: 'com.github.hierynomus.license'
  80. apply plugin: 'io.spring.dependency-management'
  81. apply plugin: 'jacoco'
  82. apply plugin: 'java'
  83. apply plugin: 'idea'
  84. apply plugin: 'org.owasp.dependencycheck'
  85. // do not deploy to Artifactory by default
  86. artifactoryPublish.skip = true
  87. ext {
  88. protobufVersion = '3.7.0'
  89. }
  90. sonarqube {
  91. properties {
  92. property 'sonar.moduleKey', project.group + ':' + project.name
  93. }
  94. }
  95. // Central place for definition dependency versions and exclusions.
  96. dependencyManagement {
  97. dependencies {
  98. // please keep this list alphabetically ordered
  99. dependencySet(group: 'ch.qos.logback', version: '1.2.3') {
  100. entry 'logback-access'
  101. entry 'logback-classic'
  102. entry 'logback-core'
  103. }
  104. dependency('commons-beanutils:commons-beanutils:1.8.3') {
  105. exclude 'commons-logging:commons-logging'
  106. }
  107. dependency 'commons-codec:commons-codec:1.12'
  108. dependency 'commons-dbutils:commons-dbutils:1.5'
  109. dependency 'commons-io:commons-io:2.6'
  110. dependency 'commons-lang:commons-lang:2.6'
  111. dependencySet(group: 'com.fasterxml.jackson.core', version: '2.9.8') {
  112. entry 'jackson-core'
  113. entry 'jackson-databind'
  114. entry 'jackson-annotations'
  115. }
  116. dependency 'com.eclipsesource.minimal-json:minimal-json:0.9.5'
  117. dependency 'com.github.kevinsawicki:http-request:5.4.1'
  118. dependency 'com.googlecode.java-diff-utils:diffutils:1.2'
  119. dependency('com.googlecode.json-simple:json-simple:1.1.1') {
  120. exclude 'junit:junit'
  121. }
  122. dependency 'com.google.code.findbugs:jsr305:3.0.2'
  123. dependency 'com.google.code.gson:gson:2.8.4'
  124. dependency 'com.google.guava:guava:18.0'
  125. dependency "com.google.protobuf:protobuf-java:${protobufVersion}"
  126. dependency 'com.h2database:h2:1.3.176'
  127. dependencySet(group: 'com.hazelcast', version: '3.8.6') {
  128. entry 'hazelcast'
  129. entry 'hazelcast-client'
  130. }
  131. dependency 'com.ibm.icu:icu4j:3.4.4'
  132. dependency 'com.microsoft.sqlserver:mssql-jdbc:7.2.2.jre11'
  133. dependency 'com.oracle.jdbc:ojdbc8:19.3'
  134. dependencySet(group: 'com.squareup.okhttp3', version: '3.14.2') {
  135. entry 'okhttp'
  136. entry 'mockwebserver'
  137. }
  138. dependency 'com.tngtech.java:junit-dataprovider:1.9.2'
  139. dependency 'info.picocli:picocli:3.6.1'
  140. dependency 'io.jsonwebtoken:jjwt-api:0.10.5'
  141. dependency 'io.jsonwebtoken:jjwt-impl:0.10.5'
  142. dependency 'io.jsonwebtoken:jjwt-jackson:0.10.5'
  143. dependency 'io.netty:netty-all:4.0.51.Final'
  144. dependency 'com.sun.mail:javax.mail:1.5.6'
  145. dependency 'javax.annotation:javax.annotation-api:1.3.1'
  146. dependency 'javax.servlet:javax.servlet-api:3.0.1'
  147. dependency 'javax.xml.bind:jaxb-api:2.3.0'
  148. dependency 'junit:junit:4.12'
  149. dependency 'net.jpountz.lz4:lz4:1.3.0'
  150. dependency 'net.lightbody.bmp:littleproxy:1.1.0-beta-bmp-17'
  151. dependency 'org.awaitility:awaitility:3.1.6'
  152. dependency 'org.apache.commons:commons-csv:1.4'
  153. dependency 'org.apache.commons:commons-email:1.5'
  154. dependency 'org.apache.commons:commons-dbcp2:2.5.0'
  155. dependency('org.apache.httpcomponents:httpclient:4.5.2'){
  156. exclude 'commons-logging:commons-logging'
  157. }
  158. // Be aware that Log4j is used by Elasticsearch client
  159. dependencySet(group: 'org.apache.logging.log4j', version: '2.8.2') {
  160. entry 'log4j-api'
  161. entry 'log4j-to-slf4j'
  162. entry 'log4j-core'
  163. }
  164. dependencySet(group: 'org.apache.tomcat.embed', version: '8.5.38') {
  165. entry 'tomcat-embed-core'
  166. entry('tomcat-embed-jasper') {
  167. exclude 'org.eclipse.jdt.core.compiler:ecj'
  168. }
  169. }
  170. dependency 'org.assertj:assertj-core:3.12.2'
  171. dependency 'org.assertj:assertj-guava:3.2.1'
  172. dependency('org.codehaus.sonar:sonar-channel:4.1') {
  173. exclude 'org.slf4j:slf4j-api'
  174. }
  175. dependency 'org.codehaus.sonar:sonar-classloader:1.0'
  176. dependency('org.codehaus.woodstox:woodstox-core-lgpl:4.4.0') {
  177. exclude 'javax.xml.stream:stax-api'
  178. }
  179. dependency 'org.codehaus.sonar.runner:sonar-runner-api:2.4'
  180. dependency('org.codehaus.sonar:sonar-squid:4.1') {
  181. exclude 'org.codehaus.sonar:sonar-check-api'
  182. }
  183. dependency('org.codehaus.staxmate:staxmate:2.0.1') {
  184. exclude 'org.codehaus.woodstox:stax2-api'
  185. exclude 'stax:stax-api'
  186. exclude 'org.codehaus.woodstox:woodstox-core-asl'
  187. }
  188. dependency('org.codehaus.woodstox:stax2-api:3.1.4') {
  189. exclude 'stax:stax-api'
  190. }
  191. dependency('org.dbunit:dbunit:2.4.5') {
  192. exclude 'commons-lang:commons-lang'
  193. exclude 'xerces:xmlParserAPIs'
  194. exclude 'xerces:xercesImpl'
  195. }
  196. dependencySet(group: 'org.eclipse.jetty', version: '9.4.6.v20170531') {
  197. entry 'jetty-proxy'
  198. entry 'jetty-server'
  199. entry 'jetty-servlet'
  200. }
  201. dependency('org.elasticsearch.client:transport:6.8.0') {
  202. exclude 'org.elasticsearch.plugin:lang-mustache-client'
  203. exclude 'commons-logging:commons-logging'
  204. exclude 'org.elasticsearch.plugin:reindex-client'
  205. exclude 'org.elasticsearch.plugin:rank-eval-client'
  206. }
  207. dependency 'org.elasticsearch:mocksocket:1.0'
  208. dependency 'org.codelibs.elasticsearch.module:analysis-common:6.8.0'
  209. dependency 'org.freemarker:freemarker:2.3.20'
  210. dependency 'org.hamcrest:hamcrest-all:1.3'
  211. dependency 'org.jsoup:jsoup:1.11.3'
  212. dependency 'org.mindrot:jbcrypt:0.4'
  213. dependency('org.mockito:mockito-core:2.22.0') {
  214. exclude 'org.hamcrest:hamcrest-core'
  215. }
  216. dependency 'org.mybatis:mybatis:3.5.1'
  217. dependency 'org.nanohttpd:nanohttpd:2.3.0'
  218. dependency 'org.picocontainer:picocontainer:2.15'
  219. dependencySet(group: 'org.slf4j', version: '1.7.25') {
  220. entry 'jcl-over-slf4j'
  221. entry 'jul-to-slf4j'
  222. entry 'log4j-over-slf4j'
  223. entry 'slf4j-api'
  224. }
  225. dependency 'org.postgresql:postgresql:42.2.5'
  226. dependency 'org.reflections:reflections:0.9.9'
  227. dependency 'org.simpleframework:simple:4.1.21'
  228. dependency 'org.sonarsource.orchestrator:sonar-orchestrator:3.26.0.2111'
  229. dependency 'org.sonarsource.update-center:sonar-update-center-common:1.18.0.487'
  230. dependency 'org.subethamail:subethasmtp:3.1.7'
  231. dependency 'org.yaml:snakeyaml:1.17'
  232. dependency 'xml-apis:xml-apis:1.4.01'
  233. // please keep this list alphabetically ordered
  234. }
  235. }
  236. // global exclusions
  237. configurations.all {
  238. // do not conflict with com.sun.mail:javax.mail
  239. exclude group: 'javax.mail', module: 'mail'
  240. }
  241. tasks.withType(JavaCompile) {
  242. options.compilerArgs.addAll(['--release', '8'])
  243. options.encoding = 'UTF-8'
  244. // redudant, just for IDEs to set the correct language level
  245. sourceCompatibility = 1.8
  246. targetCompatibility = 1.8
  247. }
  248. tasks.withType(Javadoc) {
  249. options.addStringOption('Xdoclint:none', '-quiet')
  250. options.encoding = 'UTF-8'
  251. title = project.name + ' ' + versionWithoutBuildNumber
  252. }
  253. task sourcesJar(type: Jar, dependsOn: classes) {
  254. classifier = 'sources'
  255. from sourceSets.main.allSource
  256. }
  257. task javadocJar(type: Jar, dependsOn: javadoc) {
  258. classifier = 'javadoc'
  259. from javadoc.destinationDir
  260. }
  261. // generate code before opening project in IDE (Eclipse or Intellij)
  262. task ide() {
  263. // empty by default. Dependencies are added to the task
  264. // when needed (see protobuf modules for example)
  265. }
  266. jacocoTestReport {
  267. reports {
  268. xml.enabled true
  269. csv.enabled false
  270. html.enabled false
  271. }
  272. }
  273. normalization {
  274. runtimeClasspath {
  275. // Following classpath resources contain volatile data that changes in each CI build (build number, commit id, time),
  276. // so we exclude them from calculation of build cache key of test tasks:
  277. ignore 'META-INF/MANIFEST.MF'
  278. ignore 'sonar-api-version.txt'
  279. ignore 'sq-version.txt'
  280. }
  281. }
  282. test {
  283. jvmArgs '-Dfile.encoding=UTF8'
  284. maxHeapSize = '1G'
  285. systemProperty 'java.awt.headless', true
  286. testLogging {
  287. events "skipped", "failed" // verbose log for failed and skipped tests (by default the name of the tests are not logged)
  288. exceptionFormat 'full' // log the full stack trace (default is the 1st line of the stack trace)
  289. }
  290. jacoco {
  291. enabled = true // do not disable recording of code coverage, so that remote Gradle cache entry can be used locally
  292. includes = ['com.sonar.*', 'com.sonarsource.*', 'org.sonar.*', 'org.sonarqube.*', 'org.sonarsource.*', 'io.sonarcloud.*']
  293. }
  294. if (project.hasProperty('maxParallelTests')) {
  295. maxParallelForks = project.maxParallelTests as int
  296. }
  297. if (project.hasProperty('parallelTests')) {
  298. // See https://guides.gradle.org/performance/#parallel_test_execution
  299. maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
  300. }
  301. }
  302. def protoMainSrc = 'src/main/protobuf'
  303. def protoTestSrc = 'src/test/protobuf'
  304. if (file(protoMainSrc).exists() || file(protoTestSrc).exists()) {
  305. // protobuf must be applied after java
  306. apply plugin: 'com.google.protobuf'
  307. sourceSets.main.proto.srcDir protoMainSrc // in addition to the default 'src/main/proto'
  308. sourceSets.test.proto.srcDir protoTestSrc // in addition to the default 'src/test/proto'
  309. protobuf {
  310. protoc {
  311. artifact = "com.google.protobuf:protoc:3.5.1"
  312. }
  313. }
  314. jar {
  315. exclude('**/*.proto')
  316. }
  317. idea {
  318. module {
  319. sourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java")
  320. testSourceDirs += file("${protobuf.generatedFilesBaseDir}/test/java")
  321. generatedSourceDirs += file("${protobuf.generatedFilesBaseDir}/main/java")
  322. generatedSourceDirs += file("${protobuf.generatedFilesBaseDir}/test/java")
  323. }
  324. }
  325. ide.dependsOn(['generateProto', 'generateTestProto'])
  326. }
  327. if (file('package.json').exists()) {
  328. apply plugin: 'com.moowork.node'
  329. node {
  330. version = '10.15.3'
  331. yarnVersion = '1.15.2'
  332. download = true
  333. }
  334. }
  335. if (official) {
  336. jar {
  337. // do not break incremental build on non official versions
  338. manifest {
  339. attributes(
  340. 'Version': "${version}",
  341. 'Implementation-Build': System.getenv('GIT_SHA1'),
  342. 'Build-Time': new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
  343. )
  344. }
  345. }
  346. }
  347. license {
  348. header = rootProject.file('HEADER')
  349. strictCheck true
  350. mapping {
  351. java = 'SLASHSTAR_STYLE'
  352. js = 'SLASHSTAR_STYLE'
  353. ts = 'SLASHSTAR_STYLE'
  354. tsx = 'SLASHSTAR_STYLE'
  355. css = 'SLASHSTAR_STYLE'
  356. }
  357. includes(['**/*.java', '**/*.js', '**/*.ts', '**/*.tsx', '**/*.css'])
  358. }
  359. publishing {
  360. publications {
  361. mavenJava(MavenPublication) {
  362. pom {
  363. name = 'SonarQube'
  364. description = project.description
  365. url = 'http://www.sonarqube.org/'
  366. organization {
  367. name = 'SonarSource'
  368. url = 'http://www.sonarsource.com'
  369. }
  370. licenses {
  371. license {
  372. name = 'GNU LGPL 3'
  373. url = 'http://www.gnu.org/licenses/lgpl.txt'
  374. distribution = 'repo'
  375. }
  376. }
  377. scm {
  378. url = 'https://github.com/SonarSource/sonarqube'
  379. }
  380. developers {
  381. developer {
  382. id = 'sonarsource-team'
  383. name = 'SonarSource Team'
  384. }
  385. }
  386. }
  387. }
  388. }
  389. }
  390. }
  391. // Yarn doesn't support concurrent access to its global cache,
  392. // i.e. parallel execution of several "yarn install" tasks,
  393. // since these tasks are independent, we can establish arbitrary total order
  394. // to prevent their concurrent execution:
  395. def yarnInstallTasks = allprojects.findResults { it -> it.tasks.findByName('yarn') }
  396. yarnInstallTasks.eachWithIndex { it, i -> if (i > 0) it.mustRunAfter(yarnInstallTasks.get(i - 1)) }
  397. artifactory {
  398. clientConfig.setIncludeEnvVars(true)
  399. clientConfig.setEnvVarsExcludePatterns('*password*,*PASSWORD*,*secret*,*MAVEN_CMD_LINE_ARGS*,sun.java.command,*token*,*TOKEN*,*LOGIN*,*login*,*key*,*KEY*')
  400. contextUrl = System.getenv('ARTIFACTORY_URL')
  401. publish {
  402. repository {
  403. repoKey = System.getenv('ARTIFACTORY_DEPLOY_REPO')
  404. username = System.getenv('ARTIFACTORY_DEPLOY_USERNAME') ?: project.properties.artifactoryUsername
  405. password = System.getenv('ARTIFACTORY_DEPLOY_PASSWORD') ?: project.properties.artifactoryPaswword
  406. }
  407. defaults {
  408. properties = [
  409. 'build.name': 'sonar-enterprise',
  410. 'build.number': System.getenv('BUILD_NUMBER'),
  411. 'pr.branch.target': System.getenv('GITHUB_BASE_BRANCH'),
  412. 'pr.number': System.getenv('PULL_REQUEST'),
  413. 'vcs.branch': System.getenv('GITHUB_BRANCH'),
  414. 'vcs.revision': System.getenv('GIT_SHA1'),
  415. 'version': version
  416. ]
  417. publications('mavenJava')
  418. publishPom = true
  419. publishIvy = false
  420. }
  421. }
  422. clientConfig.info.setBuildName('sonar-enterprise')
  423. clientConfig.info.setBuildNumber(System.getenv('BUILD_NUMBER'))
  424. // Define the artifacts to be deployed to https://binaries.sonarsource.com on releases
  425. clientConfig.info.addEnvironmentProperty('ARTIFACTS_TO_PUBLISH',
  426. "${project.group}:sonar-application:zip," +
  427. "com.sonarsource.sonarqube:sonarqube-developer:zip," +
  428. "com.sonarsource.sonarqube:sonarqube-datacenter:zip," +
  429. "com.sonarsource.sonarqube:sonarqube-enterprise:zip")
  430. // The name of this variable is important because it's used by the delivery process when extracting version from Artifactory build info.
  431. clientConfig.info.addEnvironmentProperty('PROJECT_VERSION', "${version}")
  432. }
  433. // https://github.com/ben-manes/gradle-versions-plugin
  434. apply plugin: 'com.github.ben-manes.versions'
  435. // Exclude dev versions from the list of dependency upgrades, for
  436. // example to replace:
  437. // org.slf4j:log4j-over-slf4j [1.7.25 -> 1.8.0-beta4]
  438. // by
  439. // org.slf4j:log4j-over-slf4j [1.7.25 -> 1.7.26]
  440. dependencyUpdates.resolutionStrategy {
  441. componentSelection { rules ->
  442. rules.all { ComponentSelection selection ->
  443. boolean rejected = ['alpha', 'beta', 'rc', 'cr', 'm', 'preview'].any { qualifier ->
  444. selection.candidate.version ==~ /(?i).*[.-]${qualifier}[.\d-]*/
  445. }
  446. if (rejected) {
  447. selection.reject('Development version')
  448. }
  449. }
  450. }
  451. }