-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.gradle
160 lines (142 loc) · 5.26 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
plugins {
id 'com.github.hierynomus.license' version '0.16.1'
id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
id 'com.jfrog.artifactory' version '4.28.1'
id 'org.sonarqube' version '3.3'
}
allprojects {
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'
ext {
release = project.hasProperty('release') && project.getProperty('release')
buildNumber = System.getProperty("buildNumber")
}
// Replaces the version defined in sources, usually x.y-SNAPSHOT, by a version identifying the build.
if (version.endsWith('-SNAPSHOT') && ext.buildNumber != null) {
def versionSuffix = (version.toString().count('.') == 1 ? ".0.${ext.buildNumber}" : ".${ext.buildNumber}")
version = version.replace('-SNAPSHOT', versionSuffix)
}
repositories {
def repository = project.hasProperty('qa') ? 'sonarsource-qa' : 'sonarsource'
maven {
url "https://repox.jfrog.io/repox/${repository}"
// The environment variables ARTIFACTORY_PRIVATE_USERNAME and ARTIFACTORY_PRIVATE_PASSWORD are used on QA env (Jenkins)
// On local box, please add artifactoryUsername and artifactoryPassword to ~/.gradle/gradle.properties
def artifactoryUsername = System.env.'ARTIFACTORY_PRIVATE_USERNAME' ?: (project.hasProperty('artifactoryUsername') ? project.getProperty('artifactoryUsername') : '')
def artifactoryPassword = System.env.'ARTIFACTORY_PRIVATE_PASSWORD' ?: (project.hasProperty('artifactoryPassword') ? project.getProperty('artifactoryPassword') : '')
if (artifactoryUsername && artifactoryPassword) {
credentials {
username = artifactoryUsername
password = artifactoryPassword
}
}
}
}
artifactory {
clientConfig.setIncludeEnvVars(true)
clientConfig.setEnvVarsExcludePatterns('*password*,*PASSWORD*,*secret*,*MAVEN_CMD_LINE_ARGS*,sun.java.command,*token*,*TOKEN*,*LOGIN*,*login*,*key*,*KEY*,*signing*')
contextUrl = System.getenv('ARTIFACTORY_URL')
publish {
repository {
repoKey = System.getenv('ARTIFACTORY_DEPLOY_REPO')
username = System.getenv('ARTIFACTORY_DEPLOY_USERNAME') ?: project.properties.artifactoryUsername
password = System.getenv('ARTIFACTORY_DEPLOY_PASSWORD') ?: project.properties.artifactoryPaswword
}
defaults {
properties = [
'build.name': 'sonar-plugin-api',
'build.number': System.getenv('BUILD_NUMBER'),
'pr.branch.target': System.getenv('PULL_REQUEST_BRANCH_TARGET'),
'pr.number': System.getenv('PULL_REQUEST_NUMBER'),
'vcs.branch': System.getenv('GITHUB_BRANCH'),
'vcs.revision': System.getenv('GIT_COMMIT'),
'version': version
]
publications('mavenJava')
publishPom = true
publishIvy = false
}
}
clientConfig.info.setBuildName('sonar-plugin-api')
clientConfig.info.setBuildNumber(System.getenv('BUILD_NUMBER'))
// The name of this variable is important because it's used by the delivery process when extracting version from Artifactory build info.
clientConfig.info.addEnvironmentProperty('PROJECT_VERSION', "${version}")
}
}
sonarqube {
properties {
property 'sonar.buildString', version
}
}
subprojects {
apply plugin: 'com.github.hierynomus.license'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'jacoco'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
jacoco {
toolVersion = "0.8.7"
}
jacocoTestReport {
reports {
xml.required = true
csv.required = false
html.required = false
}
}
license {
header = rootProject.file('HEADER')
strictCheck true
encoding = 'UTF-8'
mapping {
java = 'SLASHSTAR_STYLE'
js = 'SLASHSTAR_STYLE'
ts = 'SLASHSTAR_STYLE'
tsx = 'SLASHSTAR_STYLE'
css = 'SLASHSTAR_STYLE'
}
includes(['**/*.java', '**/*.js', '**/*.ts', '**/*.tsx', '**/*.css'])
}
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
options.encoding = 'UTF-8'
doFirst {
options.addBooleanOption('-no-module-directories', true)
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier = 'sources'
from sourceSets.main.allSource
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
rootProject.tasks["sonarqube"].dependsOn jacocoTestReport
apply plugin: 'signing'
signing {
def signingKeyId = findProperty("signingKeyId")
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
required {
def branch = System.getenv()["CIRRUS_BRANCH"]
return (branch == 'master' || branch ==~ 'branch-[\\d.]+') &&
gradle.taskGraph.hasTask(":artifactoryPublish")
}
sign publishing.publications
}
tasks.withType(Sign) {
onlyIf {
def branch = System.getenv()["CIRRUS_BRANCH"]
return !artifactoryPublish.skip &&
(branch == 'master' || branch ==~ 'branch-[\\d.]+') &&
gradle.taskGraph.hasTask(":artifactoryPublish")
}
}
}