forked from Dynatrace/openkit-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
187 lines (161 loc) · 5.22 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
/**
* Copyright 2018-2019 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 'com.github.hierynomus.license' version '0.15.0'
id 'ru.vyarus.animalsniffer' version '1.4.6'
id 'com.github.kt3k.coveralls' version '2.8.2'
id 'com.jfrog.bintray' version '1.8.4'
}
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 isGradle5OrAbove = getGradleMajorVersion() >= 5
sourceCompatibility = JavaVersion.VERSION_1_6
targetCompatibility = JavaVersion.VERSION_1_6
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
dependencies {
signature 'org.codehaus.mojo.signature:java16:1.1@signature'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.hamcrest', name: 'hamcrest-all', version: '1.3'
testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'
}
jar {
if (isGradle5OrAbove) {
archiveBaseName = 'openkit'
} else {
baseName = '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('TRAVIS') != null) {
// if the build is running on Travis CI, then the
// build number can be retrieved via TRAVIS_BUILD_NUMBER
buildNumber = System.getenv('TRAVIS_BUILD_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) {
if (isGradle5OrAbove) {
archiveClassifier = 'sources'
} else {
classifier = 'sources'
}
from sourceSets.main.allJava
}
task javadocZip(type: Zip, dependsOn: javadoc) {
if (isGradle5OrAbove) {
archiveBaseName = 'openkit'
archiveClassifier = 'javadoc'
} else {
baseName = 'openkit'
classifier = 'sources'
}
from javadoc.destinationDir
}
task javadocJar(type: Jar) {
if (isGradle5OrAbove) {
archiveClassifier = 'javadoc'
} else {
classifier = '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"
}
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)
}
}