-
Notifications
You must be signed in to change notification settings - Fork 34
/
build.gradle
223 lines (192 loc) · 6.82 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/**
* Copyright 2018-2021 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
buildscript {
repositories {
mavenCentral()
}
}
plugins {
id 'java'
id 'jacoco'
id 'maven-publish'
id 'signing'
id 'com.github.hierynomus.license' version '0.16.1'
id 'ru.vyarus.animalsniffer' version '1.5.3'
id 'com.github.nbaztec.coveralls-jacoco' version '1.2.15'
id 'io.github.gradle-nexus.publish-plugin' version '1.0.0'
}
group 'com.dynatrace.openkit'
version readVersion()
def title = 'Dynatrace OpenKit SDK for Java'
def vendor = 'Dynatrace LLC'
apply from: "gradle/license.gradle"
repositories {
mavenCentral()
}
def jvmsToTest = System.getenv("JVMS_TO_TEST") ?: "JAVA_HOME"
def minJavaCompatibilityVersion = JavaVersion.VERSION_1_7
sourceCompatibility = minJavaCompatibilityVersion
targetCompatibility = minJavaCompatibilityVersion
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
testing {
suites {
test(JvmTestSuite) {
dependencies {
implementation group: 'junit', name: 'junit', version: '4.12'
implementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
implementation group: 'org.mockito', name: 'mockito-core', version: '4.11.0'
}
sources {
java {
srcDirs = [ 'src/test' ]
}
}
}
test7(JvmTestSuite) {
useJUnit()
dependencies {
implementation(project)
implementation group: 'junit', name: 'junit', version: '4.12'
implementation group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
implementation group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
}
sources {
java {
srcDirs = ['src/test7', 'src/test']
exclude {
FileTreeElement file -> {
if(file.directory) {
// We only check files not directories
return false;
} else {
// Check if the same test is available in the normal test folder
if(file.file.absolutePath.contains("${File.separator}test${File.separator}")) {
return new File(file.file.absolutePath.replace("${File.separator}test${File.separator}",
"${File.separator}test7${File.separator}")).exists()
} else {
return false;
}
}
}
}
}
}
}
}
}
dependencies {
signature 'org.codehaus.mojo.signature:java17:1.0@signature'
}
jar {
archiveBaseName = 'openkit'
// split version into specification & implementation version
def specVersion = version
def implVersion = ''
def splitIndex = version.indexOf('-')
if (splitIndex != -1) {
implVersion = version.substring(splitIndex + 1)
specVersion = version.take(splitIndex)
}
// append build information to the spec version
def buildNumber
if (System.getenv('GITHUB_ACTIONS') != null) {
// if the build is running on Github, then the
// build number can be retrieved via GITHUB_RUN_NUMBER
buildNumber = System.getenv('GITHUB_RUN_NUMBER')
} else {
// otherwise via BUILD_NUMBER
buildNumber = System.getenv('BUILD_NUMBER')
}
if (buildNumber != null) {
if (implVersion?.trim()) {
// SNAPSHOT release or release candidate
implVersion = "${implVersion}-b${buildNumber}"
} else {
// release
implVersion = "b${buildNumber}"
}
}
def name = group.replaceAll('\\.', '/')
manifest {
attributes 'Name': "${name}/",
'Specification-Title': title,
'Specification-Version': specVersion,
'Specification-Vendor': vendor,
'Implementation-Title': group,
'Implementation-Version': implVersion,
'Implementation-Vendor': vendor,
'url': 'https://github.com/Dynatrace/openkit-java'
}
}
task sourceJar(type: Jar) {
archiveClassifier = 'sources'
from sourceSets.main.allJava
}
task javadocZip(type: Zip, dependsOn: javadoc) {
archiveBaseName = 'openkit'
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}
task javadocJar(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc
}
apply from: "gradle/coverage.gradle"
apply from: "gradle/publish.gradle"
// run each test for every JAVA_HOME_* environment which is specified and set as environment
jvmsToTest.split(",").each { envJVM ->
if (System.getenv(envJVM) != null) {
task "test-${envJVM}"(type: Test) {
exclude '**/local/*.class'
executable = System.getenv(envJVM) + "/bin/java"
if(envJVM == "JAVA_HOME_7") {
testClassesDirs = sourceSets.test7.output.classesDirs
classpath = sourceSets.test7.runtimeClasspath
}
}
tasks.test.dependsOn tasks."test-${envJVM}"
} else {
logger.quiet("Can't find " + envJVM + ". Test ignored!")
}
}
test {
maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1
}
if (project.findProperty('test.executable') != null) {
test.executable = project.findProperty('test.executable') + "/bin/java"
}
def readVersion() {
if (version == 'unspecified') {
Properties properties = new Properties()
File propertiesFile = file("version.properties")
propertiesFile.withInputStream {
properties.load(it)
}
if (properties.version != null) {
return properties.version
}
}
return version
}
def getGradleMajorVersion() {
def majorMinorSeparatorIndex = gradle.gradleVersion.indexOf('.')
if (majorMinorSeparatorIndex != -1) {
return Integer.parseInt(gradle.gradleVersion.substring(0, majorMinorSeparatorIndex))
} else {
return Integer.parseInt(gradle.gradleVersion)
}
}