-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathbuild.gradle
154 lines (134 loc) · 5.11 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
plugins {
id "java-library"
id "maven-publish"
}
description = "gRPC: Jakarta Servlet"
// Set up classpaths and source directories for different servlet tests
sourceSets {
// Only run these tests if the required minimum Java version is being used
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
jettyTest {
java {
include '**/Jetty*.java'
}
}
}
if (JavaVersion.current().isJava11Compatible()) {
tomcatTest {
java {
include '**/Tomcat*.java'
}
}
undertowTest {
java {
include '**/Undertow*.java'
}
}
}
}
configurations {
itImplementation.extendsFrom(implementation)
jettyTestImplementation.extendsFrom(itImplementation)
tomcatTestImplementation.extendsFrom(itImplementation)
undertowTestImplementation.extendsFrom(itImplementation)
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
// Mechanically transform sources from grpc-servlet to use the corrected packages
def migrate(String name, String inputDir, SourceSet sourceSet) {
def outputDir = layout.buildDirectory.dir('generated/sources/jakarta-' + name)
sourceSet.java.srcDir tasks.register('migrateSources' + name.capitalize(), Sync) { task ->
into(outputDir)
// Increment when changing the filter, to inform Gradle it needs to rebuild
inputs.property("filter-version", "1")
from("$inputDir/io/grpc/servlet") {
into('io/grpc/servlet/jakarta')
filter { String line ->
line.replace('javax.servlet', 'jakarta.servlet')
.replace('io.grpc.servlet', 'io.grpc.servlet.jakarta')
.replace('org.eclipse.jetty.http2.parser', 'org.eclipse.jetty.http2')
.replace('org.eclipse.jetty.servlet', 'org.eclipse.jetty.ee10.servlet')
}
}
}
}
migrate('main', '../src/main/java', sourceSets.main)
// Only build sourceSets and classpaths for tests if using the required minimum Java version
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
migrate('jettyTest', '../src/jettyTest/java', sourceSets.jettyTest)
}
if (JavaVersion.current().isJava11Compatible()) {
migrate('tomcatTest', '../src/tomcatTest/java', sourceSets.tomcatTest)
migrate('undertowTest', '../src/undertowTest/java', sourceSets.undertowTest)
}
// Disable checkstyle for this project, since it consists only of generated code
tasks.withType(Checkstyle).configureEach {
enabled = false
}
tasks.named("jar").configure {
manifest {
attributes('Automatic-Module-Name': 'io.grpc.servlet.jakarta')
}
}
dependencies {
api project(':grpc-api')
compileOnly libraries.jakarta.servlet.api,
libraries.javax.annotation
implementation project(':grpc-util'),
project(':grpc-core'),
libraries.guava
itImplementation project(':grpc-servlet-jakarta'),
project(':grpc-netty'),
testFixtures(project(':grpc-core')),
libraries.junit
itImplementation(project(':grpc-interop-testing')) {
// Avoid grpc-netty-shaded dependency
exclude group: 'io.grpc', module: 'grpc-alts'
exclude group: 'io.grpc', module: 'grpc-xds'
}
tomcatTestImplementation libraries.tomcat.embed.core
jettyTestImplementation libraries.jetty.servlet,
libraries.jetty.http2.server
undertowTestImplementation libraries.undertow.servlet
}
// Set up individual classpaths for each test, to avoid any mismatch,
// and ensure they are only used when supported by the current jvm
if (JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_17)) {
def jetty11Test = tasks.register('jetty11Test', Test) {
classpath = sourceSets.jettyTest.runtimeClasspath
testClassesDirs = sourceSets.jettyTest.output.classesDirs
}
tasks.named('compileJettyTestJava') { JavaCompile task ->
task.options.release.set 9
}
tasks.named("check").configure {
dependsOn jetty11Test
}
}
if (JavaVersion.current().isJava11Compatible()) {
def tomcat10Test = tasks.register('tomcat10Test', Test) {
classpath = sourceSets.tomcatTest.runtimeClasspath
testClassesDirs = sourceSets.tomcatTest.output.classesDirs
// Provide a temporary directory for tomcat to be deleted after test finishes
def tomcatTempDir = "$buildDir/tomcat_catalina_base"
systemProperty 'catalina.base', tomcatTempDir
doLast {
file(tomcatTempDir).deleteDir()
}
}
tasks.named('compileTomcatTestJava') { JavaCompile task ->
task.options.release.set 11
}
def undertowTest = tasks.register('undertowTest', Test) {
classpath = sourceSets.undertowTest.runtimeClasspath
testClassesDirs = sourceSets.undertowTest.output.classesDirs
}
tasks.named('compileUndertowTestJava') { JavaCompile task ->
task.options.release.set 11
}
tasks.named("check").configure {
dependsOn tomcat10Test, undertowTest
}
}