forked from reactor/reactor-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
208 lines (169 loc) · 6.38 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
/*
* Copyright (c) 2019-2021 VMware Inc. or its affiliates, All Rights Reserved.
*
* 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
*
* https://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.
*/
import org.apache.tools.ant.filters.ReplaceTokens
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'org.unbroken-dome.test-sets'
apply plugin: 'java-library'
description = 'Reactor Tools'
testSets {
jarFileTest
javaAgentTest
buildPluginTest
}
configurations {
shaded
}
dependencies {
api project(":reactor-core")
compileOnly libs.jsr305
compileOnly libs.jsr305
shaded "net.bytebuddy:byte-buddy:$byteBuddyVersion"
shaded "net.bytebuddy:byte-buddy-agent:$byteBuddyVersion"
for (dependency in project.configurations.shaded.dependencies) {
compileOnly(dependency)
testRuntimeOnly(dependency)
javaAgentTestRuntimeOnly(dependency)
}
testImplementation platform("org.junit:junit-bom:$junitVersion")
testImplementation "org.junit.jupiter:junit-jupiter-api"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
testImplementation "org.assertj:assertj-core:$assertjVersion"
testImplementation "cglib:cglib:$cglibVersion"
jarFileTestImplementation "org.assertj:assertj-core:$assertjVersion"
buildPluginTestImplementation gradleTestKit()
buildPluginTestImplementation platform("org.junit:junit-bom:$junitVersion")
buildPluginTestImplementation "org.junit.jupiter:junit-jupiter-api"
buildPluginTestRuntimeOnly "org.junit.jupiter:junit-jupiter-engine"
}
test {
// Creates a JVM per test because the agent can be installed only once
forkEvery = 1
maxParallelForks = 1
jvmArgs = [
"-Xverify:all",
JavaVersion.current().isJava9Compatible()
? "-Xlog:redefine+class*=warning"
: "-XX:TraceRedefineClasses=2"
]
}
jar {
archiveClassifier.set('original')
manifest {
attributes(
'Can-Retransform-Classes': 'true',
'Can-Redefine-Classes': 'true',
'Premain-Class': 'reactor.tools.agent.ReactorDebugAgent',
)
}
}
shadowJar {
classifier = null
dependsOn(project.tasks.jar)
manifest {
inheritFrom project.tasks.jar.manifest
}
configurations = [project.configurations.shaded]
project.afterEvaluate {
dependencies {
def shadedDependencies = project.configurations
.shaded
.dependencies
.collect { "${it.group}:${it.name}".toString() }
.toSet()
// Exclude every compile-scoped dependency (including the transitive ones)
for (id in project.configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts*.moduleVersion*.id) {
def module = "${id.group}:${id.name}".toString()
if (!shadedDependencies.contains(module)) {
project.configurations.shaded.exclude(group: id.group, module: id.name)
exclude(dependency(module))
}
}
}
}
exclude 'META-INF/**'
// TODO discuss with ByteBuddy folks how to shade it
exclude 'win32-x86*/**'
}
project.tasks.build.dependsOn(shadowJar)
task relocateShadowJar(type: com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation) {
target = tasks.shadowJar
prefix = "reactor.tools.shaded"
}
tasks.shadowJar.dependsOn tasks.relocateShadowJar
project.tasks.jarFileTest.configure {
systemProperty("jarFile", shadowJar.outputs.files.singleFile)
dependsOn(shadowJar)
}
project.tasks.check.dependsOn(jarFileTest)
task shadedJarTest(type: Test) {
testClassesDirs = sourceSets.test.output.classesDirs
Set<? super File> mainOutputs = [
project.sourceSets.main.output.resourcesDir,
project.sourceSets.main.java.classesDirectory,
]
classpath = shadowJar.outputs.files
// Exclude main outputs since we have the shaded JAR on the classpath already
classpath += sourceSets.test.runtimeClasspath.filter { !(it in mainOutputs) }
dependsOn(shadowJar)
}
project.tasks.check.dependsOn(shadedJarTest)
javaAgentTest {
dependsOn(tasks.shadowJar)
jvmArgs = [
"-javaagent:${shadowJar.outputs.files.singleFile}",
"-Xverify:all",
JavaVersion.current().isJava9Compatible()
? "-Xlog:redefine+class*=warning"
: "-XX:TraceRedefineClasses=2"
]
}
project.tasks.check.dependsOn(javaAgentTest)
project.tasks.buildPluginTest.mustRunAfter(shadowJar)
project.tasks.buildPluginTest.dependsOn(shadowJar)
task generateMockGradle(type: Copy) {
def coreJar = rootProject.findProject("reactor-core").buildDir.toString() + "/libs/reactor-core-" + version + ".jar"
def agentJar = buildDir.toString() + "/libs/reactor-tools-" + version + "-original.jar"
def mockGradleDir = buildDir.toString() + "/mock-gradle"
from "$projectDir/src/buildPluginTest/resources/mock-gradle"
into "$mockGradleDir"
filter(ReplaceTokens, tokens: [
CORE: coreJar,
AGENT: agentJar,
REACTIVE_STREAMS_VERSION: libs.versions.reactiveStreams.get(),
JUNIT_BOM_VERSION: "$junitVersion".toString(),
BYTE_BUDDY_VERSION: "$byteBuddyVersion".toString()
])
}
buildPluginTest {
def mockGradleDir = "$buildDir/mock-gradle"
println "will run mock gradle build from $mockGradleDir"
systemProperty "mock-gradle-dir", mockGradleDir
}
project.tasks.buildPluginTest.dependsOn(generateMockGradle)
project.tasks.check.dependsOn(buildPluginTest)
tasks.withType(Test).all {
useJUnitPlatform()
}
// make the shadow jar the default artifact
['apiElements', 'runtimeElements'].each {
configurations.getByName(it).outgoing {
artifacts.clear()
artifact(shadowJar)
}
}
configurations.runtimeOnly.outgoing.artifacts.clear()
// add original jar to the publication
publishing.publications.mavenJava.artifact(jar)