| plugins { |
| id "java-library" |
| id "maven-publish" |
| } |
| |
| description = "gRPC: Servlet" |
| |
| sourceSets { |
| // Testing threading is more of a brute-force test and is very slow. No need to run it as part |
| // of normal suite. |
| threadingTest {} |
| // Create a test sourceset for each classpath - could be simplified if we made new test directories |
| undertowTest {} |
| tomcatTest {} |
| |
| // Only compile these tests if java 11+ is being used |
| if (JavaVersion.current().isJava11Compatible()) { |
| jettyTest {} |
| } |
| } |
| |
| configurations { |
| itImplementation.extendsFrom(implementation) |
| undertowTestImplementation.extendsFrom(itImplementation) |
| tomcatTestImplementation.extendsFrom(itImplementation) |
| jettyTestImplementation.extendsFrom(itImplementation) |
| } |
| |
| tasks.named("jar").configure { |
| manifest { |
| attributes('Automatic-Module-Name': 'io.grpc.servlet') |
| } |
| } |
| |
| dependencies { |
| api project(':grpc-api') |
| compileOnly libraries.javax.servlet.api, |
| libraries.javax.annotation // java 9, 10 needs it |
| |
| implementation project(':grpc-core'), |
| libraries.guava |
| |
| testImplementation libraries.javax.servlet.api |
| |
| threadingTestImplementation project(':grpc-servlet'), |
| libraries.truth, |
| libraries.javax.servlet.api, |
| libraries.lincheck |
| |
| itImplementation project(':grpc-servlet'), |
| 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' |
| } |
| |
| undertowTestImplementation libraries.undertow.servlet22 |
| |
| tomcatTestImplementation libraries.tomcat.embed.core9 |
| |
| jettyTestImplementation libraries.jetty.servlet10, |
| libraries.jetty.http2.server10, |
| libraries.jetty.client, |
| project(':grpc-testing'), |
| libraries.truth, |
| libraries.protobuf.java |
| } |
| |
| tasks.named("test").configure { |
| if (JavaVersion.current().isJava9Compatible()) { |
| jvmArgs += [ |
| // required for Lincheck |
| '--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED', |
| '--add-exports=java.base/jdk.internal.util=ALL-UNNAMED', |
| ] |
| } |
| } |
| |
| tasks.register('threadingTest', Test) { |
| classpath = sourceSets.threadingTest.runtimeClasspath |
| testClassesDirs = sourceSets.threadingTest.output.classesDirs |
| } |
| |
| tasks.named("assemble").configure { |
| dependsOn tasks.named('compileThreadingTestJava') |
| } |
| |
| // Set up individual classpaths for each test, to avoid any mismatch, |
| // and ensure they are only used when supported by the current jvm |
| def undertowTest = tasks.register('undertowTest', Test) { |
| classpath = sourceSets.undertowTest.runtimeClasspath |
| testClassesDirs = sourceSets.undertowTest.output.classesDirs |
| } |
| def tomcat9Test = tasks.register('tomcat9Test', 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() |
| } |
| |
| // tomcat-embed-core 9 presently performs illegal reflective access on |
| // java.io.ObjectStreamClass$Caches.localDescs and sun.rmi.transport.Target.ccl, |
| // see https://lists.apache.org/thread/s0xr7tk2kfkkxfjps9n7dhh4cypfdhyy |
| if (JavaVersion.current().isJava9Compatible()) { |
| jvmArgs += ['--add-opens=java.base/java.io=ALL-UNNAMED', '--add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED'] |
| } |
| } |
| |
| tasks.named("check").configure { |
| dependsOn undertowTest, tomcat9Test |
| } |
| |
| tasks.named("jacocoTestReport").configure { |
| // Must use executionData(Task...) override. The executionData(Object...) override doesn't find |
| // execution data correctly for tasks. |
| executionData undertowTest.get(), tomcat9Test.get() |
| } |
| |
| // Only run these tests if java 11+ is being used |
| if (JavaVersion.current().isJava11Compatible()) { |
| def jettyTest = tasks.register('jettyTest', Test) { |
| classpath = sourceSets.jettyTest.runtimeClasspath |
| testClassesDirs = sourceSets.jettyTest.output.classesDirs |
| } |
| tasks.named("check").configure { |
| dependsOn jettyTest |
| } |
| tasks.named("jacocoTestReport").configure { |
| // Must use executionData(Task...) override. The executionData(Object...) override doesn't |
| // find execution data correctly for tasks. |
| executionData jettyTest.get() |
| } |
| } |